@azx-pbc/axiom-compiler 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +415 -2
- package/dist/article.d.ts +12 -0
- package/dist/article.d.ts.map +1 -0
- package/dist/article.js +16 -0
- package/dist/article.js.map +1 -0
- package/dist/cli/args.d.ts +101 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +158 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/check.d.ts +2 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +33 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/compile.d.ts +2 -0
- package/dist/cli/compile.d.ts.map +1 -0
- package/dist/cli/compile.js +43 -0
- package/dist/cli/compile.js.map +1 -0
- package/dist/cli/count.d.ts +15 -0
- package/dist/cli/count.d.ts.map +1 -0
- package/dist/cli/count.js +21 -0
- package/dist/cli/count.js.map +1 -0
- package/dist/cli/dataset.d.ts +28 -0
- package/dist/cli/dataset.d.ts.map +1 -0
- package/dist/cli/dataset.js +115 -0
- package/dist/cli/dataset.js.map +1 -0
- package/dist/cli/diff.d.ts +2 -0
- package/dist/cli/diff.d.ts.map +1 -0
- package/dist/cli/diff.js +297 -0
- package/dist/cli/diff.js.map +1 -0
- package/dist/cli/explain.d.ts +2 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +95 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fields.d.ts +11 -0
- package/dist/cli/fields.d.ts.map +1 -0
- package/dist/cli/fields.js +13 -0
- package/dist/cli/fields.js.map +1 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.d.ts.map +1 -0
- package/dist/cli/main.js +40 -0
- package/dist/cli/main.js.map +1 -0
- package/dist/cli/read.d.ts +56 -0
- package/dist/cli/read.d.ts.map +1 -0
- package/dist/cli/read.js +179 -0
- package/dist/cli/read.js.map +1 -0
- package/dist/cli/render.d.ts +58 -0
- package/dist/cli/render.d.ts.map +1 -0
- package/dist/cli/render.js +422 -0
- package/dist/cli/render.js.map +1 -0
- package/dist/cli/schema.d.ts +28 -0
- package/dist/cli/schema.d.ts.map +1 -0
- package/dist/cli/schema.js +46 -0
- package/dist/cli/schema.js.map +1 -0
- package/dist/cli/suite-report.d.ts +18 -0
- package/dist/cli/suite-report.d.ts.map +1 -0
- package/dist/cli/suite-report.js +58 -0
- package/dist/cli/suite-report.js.map +1 -0
- package/dist/cli/suites.d.ts +25 -0
- package/dist/cli/suites.d.ts.map +1 -0
- package/dist/cli/suites.js +67 -0
- package/dist/cli/suites.js.map +1 -0
- package/dist/cli/terminal.d.ts +45 -0
- package/dist/cli/terminal.d.ts.map +1 -0
- package/dist/cli/terminal.js +119 -0
- package/dist/cli/terminal.js.map +1 -0
- package/dist/cli/test.d.ts +12 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +199 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/cli/usage.d.ts +15 -0
- package/dist/cli/usage.d.ts.map +1 -0
- package/dist/cli/usage.js +95 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +51 -0
- package/dist/cli.js.map +1 -0
- package/dist/compile/artifact-members.d.ts +57 -0
- package/dist/compile/artifact-members.d.ts.map +1 -0
- package/dist/compile/artifact-members.js +130 -0
- package/dist/compile/artifact-members.js.map +1 -0
- package/dist/compile/artifact.d.ts +20 -0
- package/dist/compile/artifact.d.ts.map +1 -0
- package/dist/compile/artifact.js +87 -0
- package/dist/compile/artifact.js.map +1 -0
- package/dist/compile/compilation.d.ts +46 -0
- package/dist/compile/compilation.d.ts.map +1 -0
- package/dist/compile/compilation.js +4 -0
- package/dist/compile/compilation.js.map +1 -0
- package/dist/compile/computed.d.ts +22 -0
- package/dist/compile/computed.d.ts.map +1 -0
- package/dist/compile/computed.js +245 -0
- package/dist/compile/computed.js.map +1 -0
- package/dist/compile/condition-warnings.d.ts +12 -0
- package/dist/compile/condition-warnings.d.ts.map +1 -0
- package/dist/compile/condition-warnings.js +26 -0
- package/dist/compile/condition-warnings.js.map +1 -0
- package/dist/compile/conditions.d.ts +18 -0
- package/dist/compile/conditions.d.ts.map +1 -0
- package/dist/compile/conditions.js +22 -0
- package/dist/compile/conditions.js.map +1 -0
- package/dist/compile/cross-checks.d.ts +67 -0
- package/dist/compile/cross-checks.d.ts.map +1 -0
- package/dist/compile/cross-checks.js +238 -0
- package/dist/compile/cross-checks.js.map +1 -0
- package/dist/compile/datasets.d.ts +52 -0
- package/dist/compile/datasets.d.ts.map +1 -0
- package/dist/compile/datasets.js +183 -0
- package/dist/compile/datasets.js.map +1 -0
- package/dist/compile/dead-weight.d.ts +26 -0
- package/dist/compile/dead-weight.d.ts.map +1 -0
- package/dist/compile/dead-weight.js +244 -0
- package/dist/compile/dead-weight.js.map +1 -0
- package/dist/compile/declaration-rules.d.ts +54 -0
- package/dist/compile/declaration-rules.d.ts.map +1 -0
- package/dist/compile/declaration-rules.js +510 -0
- package/dist/compile/declaration-rules.js.map +1 -0
- package/dist/compile/declarations.d.ts +44 -0
- package/dist/compile/declarations.d.ts.map +1 -0
- package/dist/compile/declarations.js +160 -0
- package/dist/compile/declarations.js.map +1 -0
- package/dist/compile/document.d.ts +4 -0
- package/dist/compile/document.d.ts.map +1 -0
- package/dist/compile/document.js +13 -0
- package/dist/compile/document.js.map +1 -0
- package/dist/compile/expression.d.ts +38 -0
- package/dist/compile/expression.d.ts.map +1 -0
- package/dist/compile/expression.js +288 -0
- package/dist/compile/expression.js.map +1 -0
- package/dist/compile/hashes.d.ts +26 -0
- package/dist/compile/hashes.d.ts.map +1 -0
- package/dist/compile/hashes.js +96 -0
- package/dist/compile/hashes.js.map +1 -0
- package/dist/compile/item-targets.d.ts +12 -0
- package/dist/compile/item-targets.d.ts.map +1 -0
- package/dist/compile/item-targets.js +287 -0
- package/dist/compile/item-targets.js.map +1 -0
- package/dist/compile/messages.d.ts +8 -0
- package/dist/compile/messages.d.ts.map +1 -0
- package/dist/compile/messages.js +62 -0
- package/dist/compile/messages.js.map +1 -0
- package/dist/compile/option-availability.d.ts +51 -0
- package/dist/compile/option-availability.d.ts.map +1 -0
- package/dist/compile/option-availability.js +171 -0
- package/dist/compile/option-availability.js.map +1 -0
- package/dist/compile/option-codes.d.ts +27 -0
- package/dist/compile/option-codes.d.ts.map +1 -0
- package/dist/compile/option-codes.js +212 -0
- package/dist/compile/option-codes.js.map +1 -0
- package/dist/compile/references.d.ts +14 -0
- package/dist/compile/references.d.ts.map +1 -0
- package/dist/compile/references.js +126 -0
- package/dist/compile/references.js.map +1 -0
- package/dist/compile/rows-from.d.ts +27 -0
- package/dist/compile/rows-from.d.ts.map +1 -0
- package/dist/compile/rows-from.js +164 -0
- package/dist/compile/rows-from.js.map +1 -0
- package/dist/compile/rules.d.ts +58 -0
- package/dist/compile/rules.d.ts.map +1 -0
- package/dist/compile/rules.js +327 -0
- package/dist/compile/rules.js.map +1 -0
- package/dist/compile/suggestions.d.ts +52 -0
- package/dist/compile/suggestions.d.ts.map +1 -0
- package/dist/compile/suggestions.js +633 -0
- package/dist/compile/suggestions.js.map +1 -0
- package/dist/compile/targets.d.ts +22 -0
- package/dist/compile/targets.d.ts.map +1 -0
- package/dist/compile/targets.js +125 -0
- package/dist/compile/targets.js.map +1 -0
- package/dist/compile/types.d.ts +84 -0
- package/dist/compile/types.d.ts.map +1 -0
- package/dist/compile/types.js +2 -0
- package/dist/compile/types.js.map +1 -0
- package/dist/compile/warning.d.ts +45 -0
- package/dist/compile/warning.d.ts.map +1 -0
- package/dist/compile/warning.js +2 -0
- package/dist/compile/warning.js.map +1 -0
- package/dist/compile-yaml.d.ts +23 -0
- package/dist/compile-yaml.d.ts.map +1 -0
- package/dist/compile-yaml.js +30 -0
- package/dist/compile-yaml.js.map +1 -0
- package/dist/compile.d.ts +78 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +372 -0
- package/dist/compile.js.map +1 -0
- package/dist/csv/limits.d.ts +43 -0
- package/dist/csv/limits.d.ts.map +1 -0
- package/dist/csv/limits.js +51 -0
- package/dist/csv/limits.js.map +1 -0
- package/dist/csv/scalar.d.ts +33 -0
- package/dist/csv/scalar.d.ts.map +1 -0
- package/dist/csv/scalar.js +77 -0
- package/dist/csv/scalar.js.map +1 -0
- package/dist/datasets/csv.d.ts +46 -0
- package/dist/datasets/csv.d.ts.map +1 -0
- package/dist/datasets/csv.js +293 -0
- package/dist/datasets/csv.js.map +1 -0
- package/dist/datasets/declaration.d.ts +16 -0
- package/dist/datasets/declaration.d.ts.map +1 -0
- package/dist/datasets/declaration.js +104 -0
- package/dist/datasets/declaration.js.map +1 -0
- package/dist/datasets/diagnostics.d.ts +65 -0
- package/dist/datasets/diagnostics.d.ts.map +1 -0
- package/dist/datasets/diagnostics.js +2 -0
- package/dist/datasets/diagnostics.js.map +1 -0
- package/dist/datasets/diff.d.ts +46 -0
- package/dist/datasets/diff.d.ts.map +1 -0
- package/dist/datasets/diff.js +84 -0
- package/dist/datasets/diff.js.map +1 -0
- package/dist/datasets/document.d.ts +12 -0
- package/dist/datasets/document.d.ts.map +1 -0
- package/dist/datasets/document.js +382 -0
- package/dist/datasets/document.js.map +1 -0
- package/dist/datasets/index.d.ts +43 -0
- package/dist/datasets/index.d.ts.map +1 -0
- package/dist/datasets/index.js +68 -0
- package/dist/datasets/index.js.map +1 -0
- package/dist/datasets/repair.d.ts +26 -0
- package/dist/datasets/repair.d.ts.map +1 -0
- package/dist/datasets/repair.js +60 -0
- package/dist/datasets/repair.js.map +1 -0
- package/dist/document-path.d.ts +62 -0
- package/dist/document-path.d.ts.map +1 -0
- package/dist/document-path.js +200 -0
- package/dist/document-path.js.map +1 -0
- package/dist/expr/boundary.d.ts +8 -0
- package/dist/expr/boundary.d.ts.map +1 -0
- package/dist/expr/boundary.js +243 -0
- package/dist/expr/boundary.js.map +1 -0
- package/dist/expr/compile-expr.d.ts +35 -0
- package/dist/expr/compile-expr.d.ts.map +1 -0
- package/dist/expr/compile-expr.js +66 -0
- package/dist/expr/compile-expr.js.map +1 -0
- package/dist/expr/deprecation.d.ts +23 -0
- package/dist/expr/deprecation.d.ts.map +1 -0
- package/dist/expr/deprecation.js +28 -0
- package/dist/expr/deprecation.js.map +1 -0
- package/dist/expr/diagnostics.d.ts +31 -0
- package/dist/expr/diagnostics.d.ts.map +1 -0
- package/dist/expr/diagnostics.js +34 -0
- package/dist/expr/diagnostics.js.map +1 -0
- package/dist/expr/lexer.d.ts +49 -0
- package/dist/expr/lexer.d.ts.map +1 -0
- package/dist/expr/lexer.js +277 -0
- package/dist/expr/lexer.js.map +1 -0
- package/dist/expr/lint-warnings.d.ts +11 -0
- package/dist/expr/lint-warnings.d.ts.map +1 -0
- package/dist/expr/lint-warnings.js +20 -0
- package/dist/expr/lint-warnings.js.map +1 -0
- package/dist/expr/lint.d.ts +41 -0
- package/dist/expr/lint.d.ts.map +1 -0
- package/dist/expr/lint.js +1034 -0
- package/dist/expr/lint.js.map +1 -0
- package/dist/expr/parse/aggregates.d.ts +13 -0
- package/dist/expr/parse/aggregates.d.ts.map +1 -0
- package/dist/expr/parse/aggregates.js +48 -0
- package/dist/expr/parse/aggregates.js.map +1 -0
- package/dist/expr/parse/budget.d.ts +11 -0
- package/dist/expr/parse/budget.d.ts.map +1 -0
- package/dist/expr/parse/budget.js +57 -0
- package/dist/expr/parse/budget.js.map +1 -0
- package/dist/expr/parse/grammar.d.ts +9 -0
- package/dist/expr/parse/grammar.d.ts.map +1 -0
- package/dist/expr/parse/grammar.js +699 -0
- package/dist/expr/parse/grammar.js.map +1 -0
- package/dist/expr/parse/literals.d.ts +20 -0
- package/dist/expr/parse/literals.d.ts.map +1 -0
- package/dist/expr/parse/literals.js +132 -0
- package/dist/expr/parse/literals.js.map +1 -0
- package/dist/expr/parse/stream.d.ts +60 -0
- package/dist/expr/parse/stream.d.ts.map +1 -0
- package/dist/expr/parse/stream.js +151 -0
- package/dist/expr/parse/stream.js.map +1 -0
- package/dist/expr/parser.d.ts +45 -0
- package/dist/expr/parser.d.ts.map +1 -0
- package/dist/expr/parser.js +110 -0
- package/dist/expr/parser.js.map +1 -0
- package/dist/expr/print/spell.d.ts +78 -0
- package/dist/expr/print/spell.d.ts.map +1 -0
- package/dist/expr/print/spell.js +592 -0
- package/dist/expr/print/spell.js.map +1 -0
- package/dist/expr/print.d.ts +20 -0
- package/dist/expr/print.d.ts.map +1 -0
- package/dist/expr/print.js +102 -0
- package/dist/expr/print.js.map +1 -0
- package/dist/expr/suggest.d.ts +26 -0
- package/dist/expr/suggest.d.ts.map +1 -0
- package/dist/expr/suggest.js +77 -0
- package/dist/expr/suggest.js.map +1 -0
- package/dist/expr/typecheck/aggregates.d.ts +8 -0
- package/dist/expr/typecheck/aggregates.d.ts.map +1 -0
- package/dist/expr/typecheck/aggregates.js +334 -0
- package/dist/expr/typecheck/aggregates.js.map +1 -0
- package/dist/expr/typecheck/arithmetic.d.ts +6 -0
- package/dist/expr/typecheck/arithmetic.d.ts.map +1 -0
- package/dist/expr/typecheck/arithmetic.js +258 -0
- package/dist/expr/typecheck/arithmetic.js.map +1 -0
- package/dist/expr/typecheck/arity.d.ts +38 -0
- package/dist/expr/typecheck/arity.d.ts.map +1 -0
- package/dist/expr/typecheck/arity.js +173 -0
- package/dist/expr/typecheck/arity.js.map +1 -0
- package/dist/expr/typecheck/calls.d.ts +6 -0
- package/dist/expr/typecheck/calls.d.ts.map +1 -0
- package/dist/expr/typecheck/calls.js +137 -0
- package/dist/expr/typecheck/calls.js.map +1 -0
- package/dist/expr/typecheck/comparison.d.ts +13 -0
- package/dist/expr/typecheck/comparison.d.ts.map +1 -0
- package/dist/expr/typecheck/comparison.js +200 -0
- package/dist/expr/typecheck/comparison.js.map +1 -0
- package/dist/expr/typecheck/compound.d.ts +24 -0
- package/dist/expr/typecheck/compound.d.ts.map +1 -0
- package/dist/expr/typecheck/compound.js +175 -0
- package/dist/expr/typecheck/compound.js.map +1 -0
- package/dist/expr/typecheck/context.d.ts +44 -0
- package/dist/expr/typecheck/context.d.ts.map +1 -0
- package/dist/expr/typecheck/context.js +2 -0
- package/dist/expr/typecheck/context.js.map +1 -0
- package/dist/expr/typecheck/datasets.d.ts +17 -0
- package/dist/expr/typecheck/datasets.d.ts.map +1 -0
- package/dist/expr/typecheck/datasets.js +136 -0
- package/dist/expr/typecheck/datasets.js.map +1 -0
- package/dist/expr/typecheck/digest.d.ts +7 -0
- package/dist/expr/typecheck/digest.d.ts.map +1 -0
- package/dist/expr/typecheck/digest.js +44 -0
- package/dist/expr/typecheck/digest.js.map +1 -0
- package/dist/expr/typecheck/fold.d.ts +41 -0
- package/dist/expr/typecheck/fold.d.ts.map +1 -0
- package/dist/expr/typecheck/fold.js +71 -0
- package/dist/expr/typecheck/fold.js.map +1 -0
- package/dist/expr/typecheck/gate-folds.d.ts +22 -0
- package/dist/expr/typecheck/gate-folds.d.ts.map +1 -0
- package/dist/expr/typecheck/gate-folds.js +40 -0
- package/dist/expr/typecheck/gate-folds.js.map +1 -0
- package/dist/expr/typecheck/guards.d.ts +6 -0
- package/dist/expr/typecheck/guards.d.ts.map +1 -0
- package/dist/expr/typecheck/guards.js +38 -0
- package/dist/expr/typecheck/guards.js.map +1 -0
- package/dist/expr/typecheck/member.d.ts +17 -0
- package/dist/expr/typecheck/member.d.ts.map +1 -0
- package/dist/expr/typecheck/member.js +46 -0
- package/dist/expr/typecheck/member.js.map +1 -0
- package/dist/expr/typecheck/money.d.ts +8 -0
- package/dist/expr/typecheck/money.d.ts.map +1 -0
- package/dist/expr/typecheck/money.js +49 -0
- package/dist/expr/typecheck/money.js.map +1 -0
- package/dist/expr/typecheck/numeric.d.ts +8 -0
- package/dist/expr/typecheck/numeric.d.ts.map +1 -0
- package/dist/expr/typecheck/numeric.js +84 -0
- package/dist/expr/typecheck/numeric.js.map +1 -0
- package/dist/expr/typecheck/operands.d.ts +27 -0
- package/dist/expr/typecheck/operands.d.ts.map +1 -0
- package/dist/expr/typecheck/operands.js +106 -0
- package/dist/expr/typecheck/operands.js.map +1 -0
- package/dist/expr/typecheck/paths.d.ts +21 -0
- package/dist/expr/typecheck/paths.d.ts.map +1 -0
- package/dist/expr/typecheck/paths.js +321 -0
- package/dist/expr/typecheck/paths.js.map +1 -0
- package/dist/expr/typecheck/records.d.ts +24 -0
- package/dist/expr/typecheck/records.d.ts.map +1 -0
- package/dist/expr/typecheck/records.js +53 -0
- package/dist/expr/typecheck/records.js.map +1 -0
- package/dist/expr/typecheck/sequences.d.ts +15 -0
- package/dist/expr/typecheck/sequences.d.ts.map +1 -0
- package/dist/expr/typecheck/sequences.js +55 -0
- package/dist/expr/typecheck/sequences.js.map +1 -0
- package/dist/expr/typecheck/strings.d.ts +8 -0
- package/dist/expr/typecheck/strings.d.ts.map +1 -0
- package/dist/expr/typecheck/strings.js +188 -0
- package/dist/expr/typecheck/strings.js.map +1 -0
- package/dist/expr/typecheck/temporal.d.ts +7 -0
- package/dist/expr/typecheck/temporal.d.ts.map +1 -0
- package/dist/expr/typecheck/temporal.js +80 -0
- package/dist/expr/typecheck/temporal.js.map +1 -0
- package/dist/expr/typecheck/types.d.ts +163 -0
- package/dist/expr/typecheck/types.d.ts.map +1 -0
- package/dist/expr/typecheck/types.js +404 -0
- package/dist/expr/typecheck/types.js.map +1 -0
- package/dist/expr/typecheck.d.ts +75 -0
- package/dist/expr/typecheck.d.ts.map +1 -0
- package/dist/expr/typecheck.js +242 -0
- package/dist/expr/typecheck.js.map +1 -0
- package/dist/expr/undecided.d.ts +13 -0
- package/dist/expr/undecided.d.ts.map +1 -0
- package/dist/expr/undecided.js +58 -0
- package/dist/expr/undecided.js.map +1 -0
- package/dist/expr/values/code-points.d.ts +13 -0
- package/dist/expr/values/code-points.d.ts.map +1 -0
- package/dist/expr/values/code-points.js +25 -0
- package/dist/expr/values/code-points.js.map +1 -0
- package/dist/expr/values/inline.d.ts +77 -0
- package/dist/expr/values/inline.d.ts.map +1 -0
- package/dist/expr/values/inline.js +404 -0
- package/dist/expr/values/inline.js.map +1 -0
- package/dist/expr/values/interval.d.ts +19 -0
- package/dist/expr/values/interval.d.ts.map +1 -0
- package/dist/expr/values/interval.js +1180 -0
- package/dist/expr/values/interval.js.map +1 -0
- package/dist/index.d.ts +163 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +128 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest/document.d.ts +58 -0
- package/dist/ingest/document.d.ts.map +1 -0
- package/dist/ingest/document.js +83 -0
- package/dist/ingest/document.js.map +1 -0
- package/dist/ingest/yaml-document.d.ts +15 -0
- package/dist/ingest/yaml-document.d.ts.map +1 -0
- package/dist/ingest/yaml-document.js +42 -0
- package/dist/ingest/yaml-document.js.map +1 -0
- package/dist/ingest/yaml.d.ts +51 -0
- package/dist/ingest/yaml.d.ts.map +1 -0
- package/dist/ingest/yaml.js +340 -0
- package/dist/ingest/yaml.js.map +1 -0
- package/dist/layout/compile.d.ts +6 -0
- package/dist/layout/compile.d.ts.map +1 -0
- package/dist/layout/compile.js +224 -0
- package/dist/layout/compile.js.map +1 -0
- package/dist/layout/context.d.ts +12 -0
- package/dist/layout/context.d.ts.map +1 -0
- package/dist/layout/context.js +26 -0
- package/dist/layout/context.js.map +1 -0
- package/dist/layout/grammar.d.ts +34 -0
- package/dist/layout/grammar.d.ts.map +1 -0
- package/dist/layout/grammar.js +171 -0
- package/dist/layout/grammar.js.map +1 -0
- package/dist/layout/read.d.ts +54 -0
- package/dist/layout/read.d.ts.map +1 -0
- package/dist/layout/read.js +101 -0
- package/dist/layout/read.js.map +1 -0
- package/dist/layout/shape.d.ts +34 -0
- package/dist/layout/shape.d.ts.map +1 -0
- package/dist/layout/shape.js +149 -0
- package/dist/layout/shape.js.map +1 -0
- package/dist/messages/compile.d.ts +47 -0
- package/dist/messages/compile.d.ts.map +1 -0
- package/dist/messages/compile.js +202 -0
- package/dist/messages/compile.js.map +1 -0
- package/dist/messages/locale.d.ts +18 -0
- package/dist/messages/locale.d.ts.map +1 -0
- package/dist/messages/locale.js +33 -0
- package/dist/messages/locale.js.map +1 -0
- package/dist/messages/slots.d.ts +54 -0
- package/dist/messages/slots.d.ts.map +1 -0
- package/dist/messages/slots.js +137 -0
- package/dist/messages/slots.js.map +1 -0
- package/dist/overlay/compile-overlay.d.ts +29 -0
- package/dist/overlay/compile-overlay.d.ts.map +1 -0
- package/dist/overlay/compile-overlay.js +120 -0
- package/dist/overlay/compile-overlay.js.map +1 -0
- package/dist/overlay/compose.d.ts +26 -0
- package/dist/overlay/compose.d.ts.map +1 -0
- package/dist/overlay/compose.js +674 -0
- package/dist/overlay/compose.js.map +1 -0
- package/dist/overlay/types.d.ts +41 -0
- package/dist/overlay/types.d.ts.map +1 -0
- package/dist/overlay/types.js +2 -0
- package/dist/overlay/types.js.map +1 -0
- package/dist/publish/classify.d.ts +50 -0
- package/dist/publish/classify.d.ts.map +1 -0
- package/dist/publish/classify.js +85 -0
- package/dist/publish/classify.js.map +1 -0
- package/dist/publish/environment.d.ts +15 -0
- package/dist/publish/environment.d.ts.map +1 -0
- package/dist/publish/environment.js +2 -0
- package/dist/publish/environment.js.map +1 -0
- package/dist/publish/migrations.d.ts +108 -0
- package/dist/publish/migrations.d.ts.map +1 -0
- package/dist/publish/migrations.js +166 -0
- package/dist/publish/migrations.js.map +1 -0
- package/dist/publish/observation.d.ts +29 -0
- package/dist/publish/observation.d.ts.map +1 -0
- package/dist/publish/observation.js +43 -0
- package/dist/publish/observation.js.map +1 -0
- package/dist/publish/readiness.d.ts +197 -0
- package/dist/publish/readiness.d.ts.map +1 -0
- package/dist/publish/readiness.js +239 -0
- package/dist/publish/readiness.js.map +1 -0
- package/dist/publish/vectors.d.ts +50 -0
- package/dist/publish/vectors.d.ts.map +1 -0
- package/dist/publish/vectors.js +306 -0
- package/dist/publish/vectors.js.map +1 -0
- package/dist/publish/verify.d.ts +146 -0
- package/dist/publish/verify.d.ts.map +1 -0
- package/dist/publish/verify.js +548 -0
- package/dist/publish/verify.js.map +1 -0
- package/dist/scenarios/branch.d.ts +36 -0
- package/dist/scenarios/branch.d.ts.map +1 -0
- package/dist/scenarios/branch.js +30 -0
- package/dist/scenarios/branch.js.map +1 -0
- package/dist/scenarios/capture.d.ts +89 -0
- package/dist/scenarios/capture.d.ts.map +1 -0
- package/dist/scenarios/capture.js +443 -0
- package/dist/scenarios/capture.js.map +1 -0
- package/dist/scenarios/classifier.d.ts +20 -0
- package/dist/scenarios/classifier.d.ts.map +1 -0
- package/dist/scenarios/classifier.js +88 -0
- package/dist/scenarios/classifier.js.map +1 -0
- package/dist/scenarios/credit.d.ts +33 -0
- package/dist/scenarios/credit.d.ts.map +1 -0
- package/dist/scenarios/credit.js +330 -0
- package/dist/scenarios/credit.js.map +1 -0
- package/dist/scenarios/csv.d.ts +34 -0
- package/dist/scenarios/csv.d.ts.map +1 -0
- package/dist/scenarios/csv.js +1047 -0
- package/dist/scenarios/csv.js.map +1 -0
- package/dist/scenarios/data-identity.d.ts +39 -0
- package/dist/scenarios/data-identity.d.ts.map +1 -0
- package/dist/scenarios/data-identity.js +28 -0
- package/dist/scenarios/data-identity.js.map +1 -0
- package/dist/scenarios/document.d.ts +148 -0
- package/dist/scenarios/document.d.ts.map +1 -0
- package/dist/scenarios/document.js +513 -0
- package/dist/scenarios/document.js.map +1 -0
- package/dist/scenarios/environment.d.ts +64 -0
- package/dist/scenarios/environment.d.ts.map +1 -0
- package/dist/scenarios/environment.js +106 -0
- package/dist/scenarios/environment.js.map +1 -0
- package/dist/scenarios/evidence.d.ts +128 -0
- package/dist/scenarios/evidence.d.ts.map +1 -0
- package/dist/scenarios/evidence.js +179 -0
- package/dist/scenarios/evidence.js.map +1 -0
- package/dist/scenarios/expectations.d.ts +63 -0
- package/dist/scenarios/expectations.d.ts.map +1 -0
- package/dist/scenarios/expectations.js +490 -0
- package/dist/scenarios/expectations.js.map +1 -0
- package/dist/scenarios/references.d.ts +15 -0
- package/dist/scenarios/references.d.ts.map +1 -0
- package/dist/scenarios/references.js +239 -0
- package/dist/scenarios/references.js.map +1 -0
- package/dist/scenarios/report.d.ts +216 -0
- package/dist/scenarios/report.d.ts.map +1 -0
- package/dist/scenarios/report.js +54 -0
- package/dist/scenarios/report.js.map +1 -0
- package/dist/scenarios/runner.d.ts +55 -0
- package/dist/scenarios/runner.d.ts.map +1 -0
- package/dist/scenarios/runner.js +205 -0
- package/dist/scenarios/runner.js.map +1 -0
- package/dist/scenarios/vocabulary.d.ts +19 -0
- package/dist/scenarios/vocabulary.d.ts.map +1 -0
- package/dist/scenarios/vocabulary.js +56 -0
- package/dist/scenarios/vocabulary.js.map +1 -0
- package/dist/schema/catalogue.d.ts +54 -0
- package/dist/schema/catalogue.d.ts.map +1 -0
- package/dist/schema/catalogue.js +221 -0
- package/dist/schema/catalogue.js.map +1 -0
- package/dist/schema/check.d.ts +22 -0
- package/dist/schema/check.d.ts.map +1 -0
- package/dist/schema/check.js +30 -0
- package/dist/schema/check.js.map +1 -0
- package/dist/schema/closed.d.ts +19 -0
- package/dist/schema/closed.d.ts.map +1 -0
- package/dist/schema/closed.js +33 -0
- package/dist/schema/closed.js.map +1 -0
- package/dist/schema/collapse.d.ts +27 -0
- package/dist/schema/collapse.d.ts.map +1 -0
- package/dist/schema/collapse.js +143 -0
- package/dist/schema/collapse.js.map +1 -0
- package/dist/schema/controls.d.ts +46 -0
- package/dist/schema/controls.d.ts.map +1 -0
- package/dist/schema/controls.js +75 -0
- package/dist/schema/controls.js.map +1 -0
- package/dist/schema/dataset-declaration.d.ts +11 -0
- package/dist/schema/dataset-declaration.d.ts.map +1 -0
- package/dist/schema/dataset-declaration.js +11 -0
- package/dist/schema/dataset-declaration.js.map +1 -0
- package/dist/schema/declaration-warnings.d.ts +14 -0
- package/dist/schema/declaration-warnings.d.ts.map +1 -0
- package/dist/schema/declaration-warnings.js +77 -0
- package/dist/schema/declaration-warnings.js.map +1 -0
- package/dist/schema/declarations.d.ts +41 -0
- package/dist/schema/declarations.d.ts.map +1 -0
- package/dist/schema/declarations.js +1299 -0
- package/dist/schema/declarations.js.map +1 -0
- package/dist/schema/diagnostic.d.ts +118 -0
- package/dist/schema/diagnostic.d.ts.map +1 -0
- package/dist/schema/diagnostic.js +39 -0
- package/dist/schema/diagnostic.js.map +1 -0
- package/dist/schema/document.d.ts +93 -0
- package/dist/schema/document.d.ts.map +1 -0
- package/dist/schema/document.js +507 -0
- package/dist/schema/document.js.map +1 -0
- package/dist/schema/fields.d.ts +11 -0
- package/dist/schema/fields.d.ts.map +1 -0
- package/dist/schema/fields.js +265 -0
- package/dist/schema/fields.js.map +1 -0
- package/dist/schema/gates.d.ts +4 -0
- package/dist/schema/gates.d.ts.map +1 -0
- package/dist/schema/gates.js +68 -0
- package/dist/schema/gates.js.map +1 -0
- package/dist/schema/located.d.ts +27 -0
- package/dist/schema/located.d.ts.map +1 -0
- package/dist/schema/located.js +56 -0
- package/dist/schema/located.js.map +1 -0
- package/dist/schema/measurement.d.ts +9 -0
- package/dist/schema/measurement.d.ts.map +1 -0
- package/dist/schema/measurement.js +38 -0
- package/dist/schema/measurement.js.map +1 -0
- package/dist/schema/member-wording.d.ts +35 -0
- package/dist/schema/member-wording.d.ts.map +1 -0
- package/dist/schema/member-wording.js +286 -0
- package/dist/schema/member-wording.js.map +1 -0
- package/dist/schema/metaschema.d.ts +20 -0
- package/dist/schema/metaschema.d.ts.map +1 -0
- package/dist/schema/metaschema.js +476 -0
- package/dist/schema/metaschema.js.map +1 -0
- package/dist/schema/pointer.d.ts +31 -0
- package/dist/schema/pointer.d.ts.map +1 -0
- package/dist/schema/pointer.js +73 -0
- package/dist/schema/pointer.js.map +1 -0
- package/dist/schema/primary.d.ts +29 -0
- package/dist/schema/primary.d.ts.map +1 -0
- package/dist/schema/primary.js +48 -0
- package/dist/schema/primary.js.map +1 -0
- package/dist/schema/publish-vector.d.ts +17 -0
- package/dist/schema/publish-vector.d.ts.map +1 -0
- package/dist/schema/publish-vector.js +34 -0
- package/dist/schema/publish-vector.js.map +1 -0
- package/dist/schema/repair.d.ts +34 -0
- package/dist/schema/repair.d.ts.map +1 -0
- package/dist/schema/repair.js +163 -0
- package/dist/schema/repair.js.map +1 -0
- package/dist/schema/schema-v1.generated.d.ts +14 -0
- package/dist/schema/schema-v1.generated.d.ts.map +1 -0
- package/dist/schema/schema-v1.generated.js +7089 -0
- package/dist/schema/schema-v1.generated.js.map +1 -0
- package/dist/schema/screens.d.ts +4 -0
- package/dist/schema/screens.d.ts.map +1 -0
- package/dist/schema/screens.js +28 -0
- package/dist/schema/screens.js.map +1 -0
- package/dist/schema/test-values.d.ts +12 -0
- package/dist/schema/test-values.d.ts.map +1 -0
- package/dist/schema/test-values.js +97 -0
- package/dist/schema/test-values.js.map +1 -0
- package/dist/schema/unions.d.ts +46 -0
- package/dist/schema/unions.d.ts.map +1 -0
- package/dist/schema/unions.js +131 -0
- package/dist/schema/unions.js.map +1 -0
- package/dist/schema/validate-yaml.d.ts +14 -0
- package/dist/schema/validate-yaml.d.ts.map +1 -0
- package/dist/schema/validate-yaml.js +17 -0
- package/dist/schema/validate-yaml.js.map +1 -0
- package/dist/schema/validate.d.ts +46 -0
- package/dist/schema/validate.d.ts.map +1 -0
- package/dist/schema/validate.js +186 -0
- package/dist/schema/validate.js.map +1 -0
- package/dist/testing.d.ts +21 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +28 -0
- package/dist/testing.js.map +1 -0
- package/dist/vocabulary.d.ts +6 -0
- package/dist/vocabulary.d.ts.map +1 -0
- package/dist/vocabulary.js +26 -0
- package/dist/vocabulary.js.map +1 -0
- package/package.json +66 -3
|
@@ -0,0 +1,1034 @@
|
|
|
1
|
+
import { absDecimalText, asDecimalString, ceilDecimal, compareCodePoints, compareDecimalTexts, compareDurations, compareMoney, compareQuantities, divideDecimalTexts, floorDecimal, multiplyDecimalTexts, numericPower, parsePlainDate, roundDecimal, sameWireValue, subtractDecimalTexts, sumDecimalTexts, toMoneyValue, tryDecimalString, } from '@azx-pbc/axiom-runtime';
|
|
2
|
+
import { ExpressionCompileError } from './diagnostics.js';
|
|
3
|
+
import { analyzeExpression } from './values/interval.js';
|
|
4
|
+
import { codePointLength } from './values/code-points.js';
|
|
5
|
+
const MAX_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
6
|
+
/** The declarations the interval pass reads: the checker's own field map. */
|
|
7
|
+
function declarationsOf(ctx) {
|
|
8
|
+
return { fields: [...ctx.fields.values()] };
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A comparison the literal folder cannot decide, but the interval domain can: a declared
|
|
12
|
+
* `minimum`/`maximum`, literal arithmetic, an aggregate over a literal list, or a temporal
|
|
13
|
+
* accessor's value. The sentence names the fact, never the internal lattice.
|
|
14
|
+
*/
|
|
15
|
+
function intervalComparison(node, ctx) {
|
|
16
|
+
const analysis = analyzeExpression(declarationsOf(ctx), node);
|
|
17
|
+
if (!analysis.derived || analysis.truth === 'unknown')
|
|
18
|
+
return undefined;
|
|
19
|
+
return `this comparison is always ${analysis.truth} from the values its operands can take; remove it or compare against a bound a value can reach`;
|
|
20
|
+
}
|
|
21
|
+
/** Whether any operand of a same-kind connector is an inlined node that already forces the same verdict. */
|
|
22
|
+
function inlinedOperandDecidesConnector(node, truth, declarations, ctx) {
|
|
23
|
+
const stack = [...node.args];
|
|
24
|
+
while (stack.length > 0) {
|
|
25
|
+
const arg = stack.pop();
|
|
26
|
+
if (arg === undefined)
|
|
27
|
+
continue;
|
|
28
|
+
if (ctx.isInlinedNode(arg)) {
|
|
29
|
+
const inner = analyzeExpression(declarations, arg);
|
|
30
|
+
if (inner.truth === truth)
|
|
31
|
+
return true;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (arg.kind === node.kind) {
|
|
35
|
+
for (const nested of arg.args)
|
|
36
|
+
stack.push(nested);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
/** A connector whose interval is decided even when no two atoms share one bound spelling. */
|
|
42
|
+
function intervalConnector(node, ctx) {
|
|
43
|
+
const declarations = declarationsOf(ctx);
|
|
44
|
+
const analysis = analyzeExpression(declarations, node);
|
|
45
|
+
if (!analysis.derived || analysis.truth === 'unknown')
|
|
46
|
+
return undefined;
|
|
47
|
+
const decisiveTruth = node.kind === 'and' ? 'false' : 'true';
|
|
48
|
+
if (analysis.truth === decisiveTruth &&
|
|
49
|
+
inlinedOperandDecidesConnector(node, decisiveTruth, declarations, ctx)) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return analysis.truth === 'false'
|
|
53
|
+
? {
|
|
54
|
+
code: 'UNSATISFIABLE_CONDITION',
|
|
55
|
+
detail: 'the operands cannot both hold for any value the fields can take',
|
|
56
|
+
}
|
|
57
|
+
: {
|
|
58
|
+
code: 'CONSTANT_COMPARISON',
|
|
59
|
+
detail: 'the operands hold for every value the fields can take',
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function isNumericConstant(constant) {
|
|
63
|
+
return ((constant.domain === 'integer' && typeof constant.value === 'number') ||
|
|
64
|
+
(constant.domain === 'decimal' && typeof constant.value === 'string'));
|
|
65
|
+
}
|
|
66
|
+
function numericText(constant) {
|
|
67
|
+
return typeof constant.value === 'number' ? String(constant.value) : constant.value;
|
|
68
|
+
}
|
|
69
|
+
function isZero(constant) {
|
|
70
|
+
if (!isNumericConstant(constant))
|
|
71
|
+
return false;
|
|
72
|
+
return numericText(constant) === '0' || numericText(constant) === '-0';
|
|
73
|
+
}
|
|
74
|
+
function sameDomain(left, right) {
|
|
75
|
+
return left.domain === right.domain;
|
|
76
|
+
}
|
|
77
|
+
/** The language's order over two constants, or `undefined` when the two domains share none. */
|
|
78
|
+
function compareConstants(left, right) {
|
|
79
|
+
if (isNumericConstant(left) && isNumericConstant(right)) {
|
|
80
|
+
if (typeof left.value === 'number' && typeof right.value === 'number') {
|
|
81
|
+
return left.value < right.value ? -1 : left.value > right.value ? 1 : 0;
|
|
82
|
+
}
|
|
83
|
+
return compareDecimalTexts(asDecimalString(numericText(left)), asDecimalString(numericText(right)));
|
|
84
|
+
}
|
|
85
|
+
if (!sameDomain(left, right))
|
|
86
|
+
return undefined;
|
|
87
|
+
switch (left.domain) {
|
|
88
|
+
case 'string':
|
|
89
|
+
case 'date':
|
|
90
|
+
case 'instant':
|
|
91
|
+
case 'time':
|
|
92
|
+
return typeof left.value === 'string' && typeof right.value === 'string'
|
|
93
|
+
? compareCodePoints(left.value, right.value)
|
|
94
|
+
: undefined;
|
|
95
|
+
case 'money':
|
|
96
|
+
return compareMoney(toMoneyValue(left.value), toMoneyValue(right.value));
|
|
97
|
+
case 'quantity':
|
|
98
|
+
return compareQuantities(left.value, right.value);
|
|
99
|
+
case 'duration':
|
|
100
|
+
return compareDurations(left.value, right.value);
|
|
101
|
+
default:
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Equality under the language's rule, including numeric widening across integer and decimal. */
|
|
106
|
+
function equalConstants(left, right) {
|
|
107
|
+
if (isNumericConstant(left) && isNumericConstant(right)) {
|
|
108
|
+
return compareConstants(left, right) === 0;
|
|
109
|
+
}
|
|
110
|
+
if (!sameDomain(left, right))
|
|
111
|
+
return false;
|
|
112
|
+
return sameWireValue(left.value, right.value);
|
|
113
|
+
}
|
|
114
|
+
function booleanConstant(value) {
|
|
115
|
+
return { domain: 'boolean', value };
|
|
116
|
+
}
|
|
117
|
+
function integerConstant(value) {
|
|
118
|
+
return Number.isSafeInteger(value) ? { domain: 'integer', value } : undefined;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Folds an expression whose every leaf is a literal, or answers `undefined` when any leaf is not
|
|
122
|
+
* a literal or an operation is outside the folder's small vocabulary.
|
|
123
|
+
*/
|
|
124
|
+
export function constantOf(node) {
|
|
125
|
+
try {
|
|
126
|
+
return fold(node);
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
// `constantOf` is an analysis, not a reader: a runtime refusal over a value means the folder
|
|
130
|
+
// found no constant, and the refusal belongs to evaluation or to the explicit literal checks.
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function fold(node) {
|
|
135
|
+
switch (node.kind) {
|
|
136
|
+
case 'literal':
|
|
137
|
+
return { domain: node.domain, value: node.value };
|
|
138
|
+
case 'list': {
|
|
139
|
+
const items = node.items.map(fold);
|
|
140
|
+
if (items.some((item) => item === undefined))
|
|
141
|
+
return undefined;
|
|
142
|
+
return { domain: 'array', value: items.map((item) => item?.value ?? null) };
|
|
143
|
+
}
|
|
144
|
+
case 'compare':
|
|
145
|
+
return foldCompare(node);
|
|
146
|
+
case 'and':
|
|
147
|
+
case 'or':
|
|
148
|
+
return foldLogical(node);
|
|
149
|
+
case 'not': {
|
|
150
|
+
const only = node.args[0] === undefined ? undefined : fold(node.args[0]);
|
|
151
|
+
return only?.domain === 'boolean' && typeof only.value === 'boolean'
|
|
152
|
+
? booleanConstant(!only.value)
|
|
153
|
+
: undefined;
|
|
154
|
+
}
|
|
155
|
+
case 'if': {
|
|
156
|
+
const [condition, thenNode, elseNode] = node.args;
|
|
157
|
+
if (condition === undefined || thenNode === undefined || elseNode === undefined) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
const folded = fold(condition);
|
|
161
|
+
if (folded?.domain !== 'boolean' || typeof folded.value !== 'boolean')
|
|
162
|
+
return undefined;
|
|
163
|
+
return fold(folded.value ? thenNode : elseNode);
|
|
164
|
+
}
|
|
165
|
+
case 'coalesce': {
|
|
166
|
+
for (const arg of node.args) {
|
|
167
|
+
const folded = fold(arg);
|
|
168
|
+
if (folded === undefined)
|
|
169
|
+
return undefined;
|
|
170
|
+
if (folded.domain !== 'null')
|
|
171
|
+
return folded;
|
|
172
|
+
}
|
|
173
|
+
return { domain: 'null', value: null };
|
|
174
|
+
}
|
|
175
|
+
case 'call':
|
|
176
|
+
return foldCall(node);
|
|
177
|
+
case 'path':
|
|
178
|
+
case 'comprehension':
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function foldCompare(node) {
|
|
183
|
+
const [leftNode, rightNode] = node.args;
|
|
184
|
+
if (leftNode === undefined || rightNode === undefined)
|
|
185
|
+
return undefined;
|
|
186
|
+
const left = fold(leftNode);
|
|
187
|
+
const right = fold(rightNode);
|
|
188
|
+
if (left === undefined || right === undefined)
|
|
189
|
+
return undefined;
|
|
190
|
+
if (node.op === 'in') {
|
|
191
|
+
// Membership needs each element's declared domain to compare numerically across integer and
|
|
192
|
+
// decimal; a bare list constant carries no such domains, so the folder leaves it to
|
|
193
|
+
// evaluation rather than guessing.
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
if (node.op === '==' || node.op === '!=') {
|
|
197
|
+
const equal = equalConstants(left, right);
|
|
198
|
+
return booleanConstant(node.op === '==' ? equal : !equal);
|
|
199
|
+
}
|
|
200
|
+
const order = compareConstants(left, right);
|
|
201
|
+
if (order === undefined)
|
|
202
|
+
return undefined;
|
|
203
|
+
switch (node.op) {
|
|
204
|
+
case '<':
|
|
205
|
+
return booleanConstant(order < 0);
|
|
206
|
+
case '<=':
|
|
207
|
+
return booleanConstant(order <= 0);
|
|
208
|
+
case '>':
|
|
209
|
+
return booleanConstant(order > 0);
|
|
210
|
+
case '>=':
|
|
211
|
+
return booleanConstant(order >= 0);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function foldLogical(node) {
|
|
215
|
+
const decisive = node.kind === 'and' ? false : true;
|
|
216
|
+
let sawUnknown = false;
|
|
217
|
+
for (const arg of node.args) {
|
|
218
|
+
const folded = fold(arg);
|
|
219
|
+
if (folded === undefined || folded.domain !== 'boolean' || typeof folded.value !== 'boolean') {
|
|
220
|
+
sawUnknown = true;
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (folded.value === decisive)
|
|
224
|
+
return booleanConstant(decisive);
|
|
225
|
+
}
|
|
226
|
+
return sawUnknown ? undefined : booleanConstant(!decisive);
|
|
227
|
+
}
|
|
228
|
+
function foldCall(node) {
|
|
229
|
+
const args = node.args.map(fold);
|
|
230
|
+
if (args.some((arg) => arg === undefined))
|
|
231
|
+
return undefined;
|
|
232
|
+
const constants = args;
|
|
233
|
+
switch (node.op) {
|
|
234
|
+
case '+':
|
|
235
|
+
case '-':
|
|
236
|
+
case '*':
|
|
237
|
+
return foldArithmetic(node.op, constants);
|
|
238
|
+
case '/': {
|
|
239
|
+
const [left, right] = constants;
|
|
240
|
+
if (!left || !right || !isNumericConstant(left) || !isNumericConstant(right))
|
|
241
|
+
return undefined;
|
|
242
|
+
if (isZero(right))
|
|
243
|
+
return undefined;
|
|
244
|
+
return {
|
|
245
|
+
domain: 'decimal',
|
|
246
|
+
value: divideDecimalTexts(asDecimalString(numericText(left)), asDecimalString(numericText(right))),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
case 'between': {
|
|
250
|
+
const [value, low, high] = constants;
|
|
251
|
+
if (value === undefined || low === undefined || high === undefined)
|
|
252
|
+
return undefined;
|
|
253
|
+
const lower = compareConstants(low, value);
|
|
254
|
+
const upper = compareConstants(value, high);
|
|
255
|
+
return lower === undefined || upper === undefined
|
|
256
|
+
? undefined
|
|
257
|
+
: booleanConstant(lower <= 0 && upper <= 0);
|
|
258
|
+
}
|
|
259
|
+
case 'len': {
|
|
260
|
+
const [operand] = constants;
|
|
261
|
+
if (operand?.domain === 'string' && typeof operand.value === 'string') {
|
|
262
|
+
return integerConstant(codePointLength(operand.value));
|
|
263
|
+
}
|
|
264
|
+
if (operand?.domain === 'array' && Array.isArray(operand.value)) {
|
|
265
|
+
return integerConstant(operand.value.length);
|
|
266
|
+
}
|
|
267
|
+
return undefined;
|
|
268
|
+
}
|
|
269
|
+
case 'starts_with':
|
|
270
|
+
case 'ends_with':
|
|
271
|
+
case 'contains': {
|
|
272
|
+
const [text, part] = constants;
|
|
273
|
+
if (text?.domain !== 'string' ||
|
|
274
|
+
typeof text.value !== 'string' ||
|
|
275
|
+
part?.domain !== 'string' ||
|
|
276
|
+
typeof part.value !== 'string') {
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
return booleanConstant(node.op === 'starts_with'
|
|
280
|
+
? text.value.startsWith(part.value)
|
|
281
|
+
: node.op === 'ends_with'
|
|
282
|
+
? text.value.endsWith(part.value)
|
|
283
|
+
: text.value.includes(part.value));
|
|
284
|
+
}
|
|
285
|
+
case 'to_decimal': {
|
|
286
|
+
const [operand] = constants;
|
|
287
|
+
if (!operand || !isNumericConstant(operand))
|
|
288
|
+
return undefined;
|
|
289
|
+
return { domain: 'decimal', value: asDecimalString(numericText(operand)) };
|
|
290
|
+
}
|
|
291
|
+
case 'to_string': {
|
|
292
|
+
const [operand] = constants;
|
|
293
|
+
if (operand === undefined)
|
|
294
|
+
return undefined;
|
|
295
|
+
if (operand.value === null)
|
|
296
|
+
return undefined;
|
|
297
|
+
if (typeof operand.value === 'string')
|
|
298
|
+
return { domain: 'string', value: operand.value };
|
|
299
|
+
if (typeof operand.value === 'number') {
|
|
300
|
+
return { domain: 'string', value: String(operand.value) };
|
|
301
|
+
}
|
|
302
|
+
if (typeof operand.value === 'boolean') {
|
|
303
|
+
return { domain: 'string', value: operand.value ? 'true' : 'false' };
|
|
304
|
+
}
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
case 'parse_integer': {
|
|
308
|
+
const [operand] = constants;
|
|
309
|
+
if (operand?.domain !== 'string' || typeof operand.value !== 'string')
|
|
310
|
+
return undefined;
|
|
311
|
+
const text = operand.value;
|
|
312
|
+
if (!/^-?(?:0|[1-9][0-9]*)$/u.test(text))
|
|
313
|
+
return { domain: 'null', value: null };
|
|
314
|
+
const value = Number(text);
|
|
315
|
+
return Number.isSafeInteger(value)
|
|
316
|
+
? { domain: 'integer', value }
|
|
317
|
+
: { domain: 'null', value: null };
|
|
318
|
+
}
|
|
319
|
+
case 'parse_decimal': {
|
|
320
|
+
const [operand] = constants;
|
|
321
|
+
if (operand?.domain !== 'string' || typeof operand.value !== 'string')
|
|
322
|
+
return undefined;
|
|
323
|
+
const canonical = tryDecimalString(operand.value);
|
|
324
|
+
return canonical === undefined
|
|
325
|
+
? { domain: 'null', value: null }
|
|
326
|
+
: { domain: 'decimal', value: canonical };
|
|
327
|
+
}
|
|
328
|
+
case '%':
|
|
329
|
+
case '//': {
|
|
330
|
+
const [left, right] = constants;
|
|
331
|
+
if (!left || !right || !isIntegerConstant(left) || !isIntegerConstant(right)) {
|
|
332
|
+
return undefined;
|
|
333
|
+
}
|
|
334
|
+
if (isZero(right))
|
|
335
|
+
return undefined;
|
|
336
|
+
const dividend = BigInt(left.value);
|
|
337
|
+
const divisor = BigInt(right.value);
|
|
338
|
+
const remainder = dividend % divisor;
|
|
339
|
+
const quotient = remainder !== 0n && remainder < 0n !== divisor < 0n
|
|
340
|
+
? dividend / divisor - 1n
|
|
341
|
+
: dividend / divisor;
|
|
342
|
+
const result = node.op === '//'
|
|
343
|
+
? quotient
|
|
344
|
+
: remainder !== 0n && remainder < 0n !== divisor < 0n
|
|
345
|
+
? remainder + divisor
|
|
346
|
+
: remainder;
|
|
347
|
+
return withinIntegerRange(result) ? integerConstant(Number(result)) : undefined;
|
|
348
|
+
}
|
|
349
|
+
case 'round':
|
|
350
|
+
case 'round_up':
|
|
351
|
+
case 'round_down':
|
|
352
|
+
case 'round_even': {
|
|
353
|
+
const [operand, places] = constants;
|
|
354
|
+
if (!operand ||
|
|
355
|
+
!isNumericConstant(operand) ||
|
|
356
|
+
places?.domain !== 'integer' ||
|
|
357
|
+
typeof places.value !== 'number') {
|
|
358
|
+
return undefined;
|
|
359
|
+
}
|
|
360
|
+
const mode = node.op === 'round'
|
|
361
|
+
? 'half_up'
|
|
362
|
+
: node.op === 'round_up'
|
|
363
|
+
? 'up'
|
|
364
|
+
: node.op === 'round_down'
|
|
365
|
+
? 'down'
|
|
366
|
+
: 'half_even';
|
|
367
|
+
return {
|
|
368
|
+
domain: 'decimal',
|
|
369
|
+
value: roundDecimal(asDecimalString(numericText(operand)), places.value, mode),
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
case 'pow': {
|
|
373
|
+
const [base, exponent] = constants;
|
|
374
|
+
if (!base ||
|
|
375
|
+
!exponent ||
|
|
376
|
+
!isNumericConstant(base) ||
|
|
377
|
+
exponent.domain !== 'integer' ||
|
|
378
|
+
typeof exponent.value !== 'number') {
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
const value = numericPower(numericText(base), exponent.value);
|
|
382
|
+
return typeof value === 'number'
|
|
383
|
+
? { domain: 'integer', value }
|
|
384
|
+
: { domain: 'decimal', value };
|
|
385
|
+
}
|
|
386
|
+
case 'abs': {
|
|
387
|
+
const [operand] = constants;
|
|
388
|
+
if (!operand || !isNumericConstant(operand))
|
|
389
|
+
return undefined;
|
|
390
|
+
if (typeof operand.value === 'number') {
|
|
391
|
+
return integerConstant(Math.abs(operand.value));
|
|
392
|
+
}
|
|
393
|
+
return { domain: 'decimal', value: absDecimalText(asDecimalString(operand.value)) };
|
|
394
|
+
}
|
|
395
|
+
case 'ceil':
|
|
396
|
+
case 'floor': {
|
|
397
|
+
const [operand] = constants;
|
|
398
|
+
if (operand?.domain !== 'decimal' || typeof operand.value !== 'string')
|
|
399
|
+
return undefined;
|
|
400
|
+
const rounded = node.op === 'ceil'
|
|
401
|
+
? ceilDecimal(asDecimalString(operand.value))
|
|
402
|
+
: floorDecimal(asDecimalString(operand.value));
|
|
403
|
+
return integerConstant(rounded);
|
|
404
|
+
}
|
|
405
|
+
case 'year':
|
|
406
|
+
case 'month':
|
|
407
|
+
case 'day': {
|
|
408
|
+
const [operand] = constants;
|
|
409
|
+
if (operand?.domain !== 'date' || typeof operand.value !== 'string')
|
|
410
|
+
return undefined;
|
|
411
|
+
const date = parsePlainDate(operand.value);
|
|
412
|
+
return integerConstant(node.op === 'year' ? date.year : node.op === 'month' ? date.month : date.day);
|
|
413
|
+
}
|
|
414
|
+
default:
|
|
415
|
+
return undefined;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
function isIntegerConstant(constant) {
|
|
419
|
+
return constant.domain === 'integer' && typeof constant.value === 'number';
|
|
420
|
+
}
|
|
421
|
+
function foldArithmetic(op, constants) {
|
|
422
|
+
if (op === '-' && constants.length === 1) {
|
|
423
|
+
const [only] = constants;
|
|
424
|
+
if (!only || !isNumericConstant(only))
|
|
425
|
+
return undefined;
|
|
426
|
+
if (typeof only.value === 'number') {
|
|
427
|
+
return withinIntegerRange(BigInt(-only.value))
|
|
428
|
+
? { domain: 'integer', value: -only.value }
|
|
429
|
+
: undefined;
|
|
430
|
+
}
|
|
431
|
+
return {
|
|
432
|
+
domain: 'decimal',
|
|
433
|
+
value: subtractDecimalTexts(asDecimalString('0'), asDecimalString(only.value)),
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
if (op === '+' && constants.every((c) => c.domain === 'string' && typeof c.value === 'string')) {
|
|
437
|
+
return { domain: 'string', value: constants.map((c) => String(c.value)).join('') };
|
|
438
|
+
}
|
|
439
|
+
if (!constants.every(isNumericConstant))
|
|
440
|
+
return undefined;
|
|
441
|
+
const numeric = constants;
|
|
442
|
+
if (numeric.every((c) => typeof c.value === 'number')) {
|
|
443
|
+
const values = numeric.map((c) => BigInt(c.value));
|
|
444
|
+
let total = values[0] ?? 0n;
|
|
445
|
+
for (const value of values.slice(1)) {
|
|
446
|
+
total = op === '+' ? total + value : op === '-' ? total - value : total * value;
|
|
447
|
+
}
|
|
448
|
+
return withinIntegerRange(total) ? { domain: 'integer', value: Number(total) } : undefined;
|
|
449
|
+
}
|
|
450
|
+
const texts = numeric.map((c) => asDecimalString(numericText(c)));
|
|
451
|
+
if (texts.length === 0)
|
|
452
|
+
return undefined;
|
|
453
|
+
const [first, ...rest] = texts;
|
|
454
|
+
if (first === undefined)
|
|
455
|
+
return undefined;
|
|
456
|
+
let total = first;
|
|
457
|
+
for (const text of rest) {
|
|
458
|
+
total =
|
|
459
|
+
op === '+'
|
|
460
|
+
? sumDecimalTexts([total, text])
|
|
461
|
+
: op === '-'
|
|
462
|
+
? subtractDecimalTexts(total, text)
|
|
463
|
+
: multiplyDecimalTexts(total, text);
|
|
464
|
+
}
|
|
465
|
+
return { domain: 'decimal', value: total };
|
|
466
|
+
}
|
|
467
|
+
function withinIntegerRange(value) {
|
|
468
|
+
return value >= -BigInt(MAX_INTEGER) && value <= BigInt(MAX_INTEGER);
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* The exact integer an integer-typed expression has, even when it leaves the canonical range.
|
|
472
|
+
*
|
|
473
|
+
* It deliberately answers a value outside the range instead of `undefined`: the lint needs to
|
|
474
|
+
* see the overflow, and a parent expression must keep folding so the first overflow is the one
|
|
475
|
+
* the author is told about.
|
|
476
|
+
*/
|
|
477
|
+
function exactInteger(node) {
|
|
478
|
+
switch (node.kind) {
|
|
479
|
+
case 'literal':
|
|
480
|
+
return node.domain === 'integer' && typeof node.value === 'number'
|
|
481
|
+
? BigInt(node.value)
|
|
482
|
+
: undefined;
|
|
483
|
+
case 'call': {
|
|
484
|
+
const args = node.args.map(exactInteger);
|
|
485
|
+
if (args.some((arg) => arg === undefined))
|
|
486
|
+
return undefined;
|
|
487
|
+
const values = args;
|
|
488
|
+
switch (node.op) {
|
|
489
|
+
case '+':
|
|
490
|
+
return values.reduce((left, right) => left + right, 0n);
|
|
491
|
+
case '-':
|
|
492
|
+
return values.length === 1
|
|
493
|
+
? -(values[0] ?? 0n)
|
|
494
|
+
: values.reduce((left, right) => left - right);
|
|
495
|
+
case '*':
|
|
496
|
+
return values.reduce((left, right) => left * right, 1n);
|
|
497
|
+
case '//': {
|
|
498
|
+
const divisor = values[1];
|
|
499
|
+
if (divisor === undefined || divisor === 0n)
|
|
500
|
+
return undefined;
|
|
501
|
+
const remainder = (values[0] ?? 0n) % divisor;
|
|
502
|
+
return remainder !== 0n && remainder < 0n !== divisor < 0n
|
|
503
|
+
? (values[0] ?? 0n) / divisor - 1n
|
|
504
|
+
: (values[0] ?? 0n) / divisor;
|
|
505
|
+
}
|
|
506
|
+
case '%': {
|
|
507
|
+
const divisor = values[1];
|
|
508
|
+
if (divisor === undefined || divisor === 0n)
|
|
509
|
+
return undefined;
|
|
510
|
+
const remainder = (values[0] ?? 0n) % divisor;
|
|
511
|
+
return remainder !== 0n && remainder < 0n !== divisor < 0n
|
|
512
|
+
? remainder + divisor
|
|
513
|
+
: remainder;
|
|
514
|
+
}
|
|
515
|
+
case 'pow': {
|
|
516
|
+
const exponent = values[1];
|
|
517
|
+
if (exponent === undefined || exponent < 0n || exponent > 10000n)
|
|
518
|
+
return undefined;
|
|
519
|
+
return (values[0] ?? 0n) ** exponent;
|
|
520
|
+
}
|
|
521
|
+
case 'abs': {
|
|
522
|
+
const only = values[0];
|
|
523
|
+
return only === undefined ? undefined : only < 0n ? -only : only;
|
|
524
|
+
}
|
|
525
|
+
default:
|
|
526
|
+
return undefined;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
default:
|
|
530
|
+
return undefined;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function integerRangeOf(node) {
|
|
534
|
+
if (node.kind !== 'call')
|
|
535
|
+
return undefined;
|
|
536
|
+
switch (node.op) {
|
|
537
|
+
case 'len':
|
|
538
|
+
case 'count_where':
|
|
539
|
+
case 'count_distinct':
|
|
540
|
+
return { min: 0, max: MAX_INTEGER };
|
|
541
|
+
case 'year':
|
|
542
|
+
return { min: 1, max: 9999 };
|
|
543
|
+
case 'month':
|
|
544
|
+
return { min: 1, max: 12 };
|
|
545
|
+
case 'day':
|
|
546
|
+
return { min: 1, max: 31 };
|
|
547
|
+
case 'weekday':
|
|
548
|
+
return { min: 1, max: 7 };
|
|
549
|
+
case 'money_scale':
|
|
550
|
+
return { min: 0, max: 6 };
|
|
551
|
+
case 'index_of':
|
|
552
|
+
return { min: -1, max: MAX_INTEGER };
|
|
553
|
+
case 'abs': {
|
|
554
|
+
const inner = node.args[0] === undefined ? undefined : integerRangeOf(node.args[0]);
|
|
555
|
+
return inner === undefined
|
|
556
|
+
? undefined
|
|
557
|
+
: { min: 0, max: Math.max(Math.abs(inner.min), Math.abs(inner.max)) };
|
|
558
|
+
}
|
|
559
|
+
default:
|
|
560
|
+
return undefined;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
/**
|
|
564
|
+
* Whether a comparison against a known range is decided for every value.
|
|
565
|
+
*
|
|
566
|
+
* `true` means always true, `false` always false, `undefined` means the range straddles the
|
|
567
|
+
* bound and the comparison still says something.
|
|
568
|
+
*/
|
|
569
|
+
function rangeVerdict(range, op, value) {
|
|
570
|
+
switch (op) {
|
|
571
|
+
case '<':
|
|
572
|
+
return range.max < value ? true : range.min >= value ? false : undefined;
|
|
573
|
+
case '<=':
|
|
574
|
+
return range.max <= value ? true : range.min > value ? false : undefined;
|
|
575
|
+
case '>':
|
|
576
|
+
return range.min > value ? true : range.max <= value ? false : undefined;
|
|
577
|
+
case '>=':
|
|
578
|
+
return range.min >= value ? true : range.max < value ? false : undefined;
|
|
579
|
+
case '==':
|
|
580
|
+
return value < range.min || value > range.max
|
|
581
|
+
? false
|
|
582
|
+
: range.min === range.max && value === range.min
|
|
583
|
+
? true
|
|
584
|
+
: undefined;
|
|
585
|
+
case '!=': {
|
|
586
|
+
const equal = rangeVerdict(range, '==', value);
|
|
587
|
+
return equal === undefined ? undefined : !equal;
|
|
588
|
+
}
|
|
589
|
+
case 'in':
|
|
590
|
+
return undefined;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
/** The mirror of one ordering operator when the range is on the right of the comparison. */
|
|
594
|
+
function mirrored(op) {
|
|
595
|
+
switch (op) {
|
|
596
|
+
case '<':
|
|
597
|
+
return '>';
|
|
598
|
+
case '<=':
|
|
599
|
+
return '>=';
|
|
600
|
+
case '>':
|
|
601
|
+
return '<';
|
|
602
|
+
case '>=':
|
|
603
|
+
return '<=';
|
|
604
|
+
default:
|
|
605
|
+
return op;
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function constantComparison(node) {
|
|
609
|
+
const [leftNode, rightNode] = node.args;
|
|
610
|
+
if (leftNode === undefined || rightNode === undefined)
|
|
611
|
+
return undefined;
|
|
612
|
+
const left = constantOf(leftNode);
|
|
613
|
+
const right = constantOf(rightNode);
|
|
614
|
+
if (left !== undefined && right !== undefined) {
|
|
615
|
+
if (node.op === 'in') {
|
|
616
|
+
if (right.domain !== 'array' || !Array.isArray(right.value))
|
|
617
|
+
return undefined;
|
|
618
|
+
const holds = right.value.some((item) => sameWireValue(item, left.value));
|
|
619
|
+
return `this \`in\` test is always ${holds ? 'true' : 'false'}; remove it or compare against a list that can hold the value`;
|
|
620
|
+
}
|
|
621
|
+
const order = node.op === '==' || node.op === '!=' ? undefined : compareConstants(left, right);
|
|
622
|
+
let holds;
|
|
623
|
+
if (node.op === '==' || node.op === '!=') {
|
|
624
|
+
const equal = equalConstants(left, right);
|
|
625
|
+
holds = node.op === '==' ? equal : !equal;
|
|
626
|
+
}
|
|
627
|
+
else if (order !== undefined) {
|
|
628
|
+
holds =
|
|
629
|
+
node.op === '<'
|
|
630
|
+
? order < 0
|
|
631
|
+
: node.op === '<='
|
|
632
|
+
? order <= 0
|
|
633
|
+
: node.op === '>'
|
|
634
|
+
? order > 0
|
|
635
|
+
: order >= 0;
|
|
636
|
+
}
|
|
637
|
+
if (holds === undefined)
|
|
638
|
+
return undefined;
|
|
639
|
+
return `this comparison is always ${holds ? 'true' : 'false'} because both operands are literals; remove it or compare values that can vary`;
|
|
640
|
+
}
|
|
641
|
+
const literalLeft = left;
|
|
642
|
+
const literalRight = right;
|
|
643
|
+
if (literalRight !== undefined && isIntegerConstant(literalRight)) {
|
|
644
|
+
const range = integerRangeOf(leftNode);
|
|
645
|
+
if (range !== undefined) {
|
|
646
|
+
const verdict = rangeVerdict(range, node.op, literalRight.value);
|
|
647
|
+
if (verdict !== undefined) {
|
|
648
|
+
return `this comparison is always ${verdict ? 'true' : 'false'} because ${describeRange(leftNode)} is ${describeRangeText(range)}; remove it or compare against a bound the value can reach`;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (literalLeft !== undefined && isIntegerConstant(literalLeft)) {
|
|
653
|
+
const range = integerRangeOf(rightNode);
|
|
654
|
+
if (range !== undefined) {
|
|
655
|
+
const verdict = rangeVerdict(range, mirrored(node.op), literalLeft.value);
|
|
656
|
+
if (verdict !== undefined) {
|
|
657
|
+
return `this comparison is always ${verdict ? 'true' : 'false'} because ${describeRange(rightNode)} is ${describeRangeText(range)}; remove it or compare against a bound the value can reach`;
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
663
|
+
function describeRange(node) {
|
|
664
|
+
return node.kind === 'call' ? `\`${node.op}(…)\`` : 'this operand';
|
|
665
|
+
}
|
|
666
|
+
function describeRangeText(range) {
|
|
667
|
+
return range.max === MAX_INTEGER
|
|
668
|
+
? `at least ${String(range.min)}`
|
|
669
|
+
: `between ${String(range.min)} and ${String(range.max)}`;
|
|
670
|
+
}
|
|
671
|
+
function atomOf(node) {
|
|
672
|
+
const [leftNode, rightNode] = node.args;
|
|
673
|
+
if (leftNode === undefined || rightNode === undefined)
|
|
674
|
+
return undefined;
|
|
675
|
+
if (leftNode.kind === 'path') {
|
|
676
|
+
const constant = constantOf(rightNode);
|
|
677
|
+
if (constant !== undefined) {
|
|
678
|
+
return { path: leftNode.path, op: node.op, value: constant };
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
if (rightNode.kind === 'path') {
|
|
682
|
+
const constant = constantOf(leftNode);
|
|
683
|
+
if (constant !== undefined) {
|
|
684
|
+
return {
|
|
685
|
+
path: rightNode.path,
|
|
686
|
+
op: mirrored(node.op),
|
|
687
|
+
value: constant,
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
return undefined;
|
|
692
|
+
}
|
|
693
|
+
function sameInlinedOrigin(left, right) {
|
|
694
|
+
return left !== undefined && left === right;
|
|
695
|
+
}
|
|
696
|
+
function walkBounds(node, isInlined) {
|
|
697
|
+
if (node.kind !== 'and' && node.kind !== 'or')
|
|
698
|
+
return undefined;
|
|
699
|
+
const atoms = [];
|
|
700
|
+
const literals = [];
|
|
701
|
+
let leaves = 0;
|
|
702
|
+
const visit = (current, inlinedRoot) => {
|
|
703
|
+
const nextInlinedRoot = inlinedRoot ?? (isInlined?.(current) === true ? current : undefined);
|
|
704
|
+
if (current.kind === node.kind) {
|
|
705
|
+
for (const arg of current.args)
|
|
706
|
+
visit(arg, nextInlinedRoot);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
leaves += 1;
|
|
710
|
+
if (current.kind === 'compare') {
|
|
711
|
+
const atom = atomOf(current);
|
|
712
|
+
if (atom !== undefined)
|
|
713
|
+
atoms.push({ atom, inlinedRoot: nextInlinedRoot });
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const constant = constantOf(current);
|
|
717
|
+
if (constant?.domain === 'boolean' && typeof constant.value === 'boolean') {
|
|
718
|
+
literals.push({ value: constant.value, inlinedRoot: nextInlinedRoot });
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
visit(node, undefined);
|
|
722
|
+
if (node.kind === 'and') {
|
|
723
|
+
if (literals.some((entry) => entry.value === false && entry.inlinedRoot === undefined)) {
|
|
724
|
+
return { kind: 'unsatisfiable', detail: 'one operand is the literal `false`' };
|
|
725
|
+
}
|
|
726
|
+
return contradictory(atoms);
|
|
727
|
+
}
|
|
728
|
+
if (literals.some((entry) => entry.value === true))
|
|
729
|
+
return undefined;
|
|
730
|
+
// Only a disjunction whose every operand is the literal `false` is unsatisfiable. An empty
|
|
731
|
+
// observation list is not that: an `or` whose operands the walk could not reduce to a literal
|
|
732
|
+
// has decided nothing, and silence is the only honest answer. The old `[].every(...)` test
|
|
733
|
+
// read that empty list as "all false" and told authors to delete correct rules.
|
|
734
|
+
if (leaves > 0 &&
|
|
735
|
+
literals.length === leaves &&
|
|
736
|
+
literals.every((entry) => entry.value === false)) {
|
|
737
|
+
const firstRoot = literals[0]?.inlinedRoot;
|
|
738
|
+
const allFromOneInlined = firstRoot !== undefined && literals.every((entry) => entry.inlinedRoot === firstRoot);
|
|
739
|
+
if (!allFromOneInlined) {
|
|
740
|
+
return { kind: 'unsatisfiable', detail: 'every operand is the literal `false`' };
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
const seen = new Map();
|
|
744
|
+
for (const { atom, inlinedRoot } of atoms) {
|
|
745
|
+
const key = `${atom.path}\u0000${atom.op}\u0000${String(atom.value.domain)}\u0000${JSON.stringify(atom.value.value)}`;
|
|
746
|
+
if (seen.has(key)) {
|
|
747
|
+
const previousRoot = seen.get(key);
|
|
748
|
+
// Two copies inside the same inlined computed definition already earned their own
|
|
749
|
+
// `REDUNDANT_CONDITION` warning on that definition's slot.
|
|
750
|
+
if (sameInlinedOrigin(inlinedRoot, previousRoot))
|
|
751
|
+
continue;
|
|
752
|
+
return {
|
|
753
|
+
kind: 'redundant',
|
|
754
|
+
detail: `\`${atom.path}\` is compared with the same bound twice, so the repeated branch states nothing the first one did not`,
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
seen.set(key, inlinedRoot);
|
|
758
|
+
}
|
|
759
|
+
return undefined;
|
|
760
|
+
}
|
|
761
|
+
function hasOwnContradiction(entries) {
|
|
762
|
+
const byPath = new Map();
|
|
763
|
+
for (const entry of entries) {
|
|
764
|
+
const list = byPath.get(entry.atom.path) ?? [];
|
|
765
|
+
list.push({ atom: entry.atom, inlinedRoot: undefined });
|
|
766
|
+
byPath.set(entry.atom.path, list);
|
|
767
|
+
}
|
|
768
|
+
for (const list of byPath.values()) {
|
|
769
|
+
if (contradictionOf(list) !== undefined)
|
|
770
|
+
return true;
|
|
771
|
+
}
|
|
772
|
+
return false;
|
|
773
|
+
}
|
|
774
|
+
function contradictory(entries) {
|
|
775
|
+
const byRoot = new Map();
|
|
776
|
+
for (const entry of entries) {
|
|
777
|
+
if (entry.inlinedRoot === undefined)
|
|
778
|
+
continue;
|
|
779
|
+
const list = byRoot.get(entry.inlinedRoot) ?? [];
|
|
780
|
+
list.push(entry);
|
|
781
|
+
byRoot.set(entry.inlinedRoot, list);
|
|
782
|
+
}
|
|
783
|
+
for (const list of byRoot.values()) {
|
|
784
|
+
// An inlined computed operand that is already self-contradictory earned
|
|
785
|
+
// `UNSATISFIABLE_CONDITION` on its own slot; match `inlinedOperandDecidesConnector` so
|
|
786
|
+
// consumer conjunctions emit no order-dependent duplicate warning.
|
|
787
|
+
if (hasOwnContradiction(list))
|
|
788
|
+
return undefined;
|
|
789
|
+
}
|
|
790
|
+
const byPath = new Map();
|
|
791
|
+
for (const entry of entries) {
|
|
792
|
+
const list = byPath.get(entry.atom.path) ?? [];
|
|
793
|
+
list.push(entry);
|
|
794
|
+
byPath.set(entry.atom.path, list);
|
|
795
|
+
}
|
|
796
|
+
for (const [path, list] of byPath) {
|
|
797
|
+
const verdict = contradictionOf(list);
|
|
798
|
+
if (verdict !== undefined) {
|
|
799
|
+
return {
|
|
800
|
+
kind: 'unsatisfiable',
|
|
801
|
+
detail: `\`${path}\` cannot satisfy both bounds: ${verdict}`,
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
return undefined;
|
|
806
|
+
}
|
|
807
|
+
function contradictionOf(entries) {
|
|
808
|
+
let lower;
|
|
809
|
+
let upper;
|
|
810
|
+
let equality;
|
|
811
|
+
const excluded = [];
|
|
812
|
+
for (const { atom, inlinedRoot } of entries) {
|
|
813
|
+
switch (atom.op) {
|
|
814
|
+
case '==':
|
|
815
|
+
if (equality !== undefined) {
|
|
816
|
+
if (!equalConstants(equality.value, atom.value) &&
|
|
817
|
+
!sameInlinedOrigin(equality.inlinedRoot, inlinedRoot)) {
|
|
818
|
+
return `\`==\` names two different values`;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
equality = { value: atom.value, inlinedRoot };
|
|
823
|
+
}
|
|
824
|
+
break;
|
|
825
|
+
case '!=':
|
|
826
|
+
excluded.push({ value: atom.value, inlinedRoot });
|
|
827
|
+
break;
|
|
828
|
+
case '>':
|
|
829
|
+
case '>=': {
|
|
830
|
+
const candidate = { value: atom.value, inclusive: atom.op === '>=', inlinedRoot };
|
|
831
|
+
if (lower === undefined)
|
|
832
|
+
lower = candidate;
|
|
833
|
+
else {
|
|
834
|
+
const order = compareConstants(candidate.value, lower.value);
|
|
835
|
+
if (order === undefined)
|
|
836
|
+
return undefined;
|
|
837
|
+
if (order > 0 || (order === 0 && lower.inclusive && !candidate.inclusive)) {
|
|
838
|
+
lower = candidate;
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
break;
|
|
842
|
+
}
|
|
843
|
+
case '<':
|
|
844
|
+
case '<=': {
|
|
845
|
+
const candidate = { value: atom.value, inclusive: atom.op === '<=', inlinedRoot };
|
|
846
|
+
if (upper === undefined)
|
|
847
|
+
upper = candidate;
|
|
848
|
+
else {
|
|
849
|
+
const order = compareConstants(candidate.value, upper.value);
|
|
850
|
+
if (order === undefined)
|
|
851
|
+
return undefined;
|
|
852
|
+
if (order < 0 || (order === 0 && upper.inclusive && !candidate.inclusive)) {
|
|
853
|
+
upper = candidate;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
case 'in':
|
|
859
|
+
break;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
if (equality !== undefined) {
|
|
863
|
+
for (const item of excluded) {
|
|
864
|
+
if (equalConstants(equality.value, item.value) &&
|
|
865
|
+
!sameInlinedOrigin(equality.inlinedRoot, item.inlinedRoot)) {
|
|
866
|
+
return `\`==\` and \`!=\` name the same value`;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
if (lower !== undefined && !sameInlinedOrigin(equality.inlinedRoot, lower.inlinedRoot)) {
|
|
870
|
+
const order = compareConstants(equality.value, lower.value);
|
|
871
|
+
if (order === undefined)
|
|
872
|
+
return undefined;
|
|
873
|
+
if (order < 0 || (order === 0 && !lower.inclusive)) {
|
|
874
|
+
return `\`==\` states a value below \`${lower.inclusive ? '>=' : '>'}\``;
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (upper !== undefined && !sameInlinedOrigin(equality.inlinedRoot, upper.inlinedRoot)) {
|
|
878
|
+
const order = compareConstants(equality.value, upper.value);
|
|
879
|
+
if (order === undefined)
|
|
880
|
+
return undefined;
|
|
881
|
+
if (order > 0 || (order === 0 && !upper.inclusive)) {
|
|
882
|
+
return `\`==\` states a value above \`${upper.inclusive ? '<=' : '<'}\``;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
if (lower === undefined || upper === undefined)
|
|
887
|
+
return undefined;
|
|
888
|
+
if (sameInlinedOrigin(lower.inlinedRoot, upper.inlinedRoot))
|
|
889
|
+
return undefined;
|
|
890
|
+
const order = compareConstants(lower.value, upper.value);
|
|
891
|
+
if (order === undefined)
|
|
892
|
+
return undefined;
|
|
893
|
+
if (order > 0)
|
|
894
|
+
return 'the lower bound is above the upper bound';
|
|
895
|
+
if (order === 0 && !(lower.inclusive && upper.inclusive)) {
|
|
896
|
+
return 'the only shared value lies outside an exclusive bound';
|
|
897
|
+
}
|
|
898
|
+
return undefined;
|
|
899
|
+
}
|
|
900
|
+
/** The literal-free reason a boolean expression can never fire, when one is provable. */
|
|
901
|
+
export function conditionNeverFires(node, declarations) {
|
|
902
|
+
const constant = constantOf(node);
|
|
903
|
+
if (constant?.domain === 'boolean' && constant.value === false) {
|
|
904
|
+
return 'the condition is the literal `false`';
|
|
905
|
+
}
|
|
906
|
+
const walk = walkBounds(node);
|
|
907
|
+
if (walk?.kind === 'unsatisfiable')
|
|
908
|
+
return walk.detail;
|
|
909
|
+
if (declarations === undefined)
|
|
910
|
+
return undefined;
|
|
911
|
+
const analysis = analyzeExpression(declarations, node);
|
|
912
|
+
if (!analysis.derived || analysis.truth !== 'false')
|
|
913
|
+
return undefined;
|
|
914
|
+
return analysis.shape === 'comparison'
|
|
915
|
+
? 'the comparison is always false from the values its operands can take'
|
|
916
|
+
: 'the intervals of its operands cannot overlap';
|
|
917
|
+
}
|
|
918
|
+
/**
|
|
919
|
+
* The findings one expression earns, errors included.
|
|
920
|
+
*
|
|
921
|
+
* A literal error throws the same `ExpressionCompileError` the type checker throws, so a caller
|
|
922
|
+
* sees one diagnostic shape. Warnings are returned because the document still compiles.
|
|
923
|
+
*/
|
|
924
|
+
export function analyseExpression(ctx, node) {
|
|
925
|
+
const findings = [];
|
|
926
|
+
visit(ctx, node, findings);
|
|
927
|
+
return findings;
|
|
928
|
+
}
|
|
929
|
+
function visit(ctx, node, findings) {
|
|
930
|
+
checkLiteralRefusal(ctx, node);
|
|
931
|
+
if (!ctx.isInlinedNode(node)) {
|
|
932
|
+
if (node.kind === 'compare') {
|
|
933
|
+
const detail = constantComparison(node) ?? intervalComparison(node, ctx);
|
|
934
|
+
if (detail !== undefined) {
|
|
935
|
+
findings.push({ code: 'CONSTANT_COMPARISON', offset: ctx.offsetOf(node), detail });
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
if (node.kind === 'call' && node.op === 'matches') {
|
|
939
|
+
const pattern = node.args[1] === undefined ? undefined : constantOf(node.args[1]);
|
|
940
|
+
if (pattern?.domain === 'string' && pattern.value === '') {
|
|
941
|
+
findings.push({
|
|
942
|
+
code: 'CONSTANT_COMPARISON',
|
|
943
|
+
offset: ctx.offsetOf(node),
|
|
944
|
+
detail: 'this `matches` tests an empty pattern, which every string matches; write the pattern the check meant or remove it',
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
if (node.kind === 'and' || node.kind === 'or') {
|
|
949
|
+
const walk = walkBounds(node, (candidate) => ctx.isInlinedNode(candidate));
|
|
950
|
+
const interval = walk === undefined ? intervalConnector(node, ctx) : undefined;
|
|
951
|
+
if (walk !== undefined || interval !== undefined) {
|
|
952
|
+
findings.push({
|
|
953
|
+
code: walk?.kind === 'redundant'
|
|
954
|
+
? 'REDUNDANT_CONDITION'
|
|
955
|
+
: (interval?.code ?? 'UNSATISFIABLE_CONDITION'),
|
|
956
|
+
offset: ctx.offsetOf(node),
|
|
957
|
+
detail: walk?.detail ?? interval?.detail ?? 'the connector can never hold',
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
switch (node.kind) {
|
|
963
|
+
case 'literal':
|
|
964
|
+
case 'path':
|
|
965
|
+
return;
|
|
966
|
+
case 'list':
|
|
967
|
+
for (const item of node.items)
|
|
968
|
+
visit(ctx, item, findings);
|
|
969
|
+
return;
|
|
970
|
+
case 'comprehension':
|
|
971
|
+
visit(ctx, node.source, findings);
|
|
972
|
+
if (node.valueExpr !== undefined)
|
|
973
|
+
visit(ctx, node.valueExpr, findings);
|
|
974
|
+
if (node.predicate !== undefined)
|
|
975
|
+
visit(ctx, node.predicate, findings);
|
|
976
|
+
return;
|
|
977
|
+
case 'not':
|
|
978
|
+
case 'and':
|
|
979
|
+
case 'or':
|
|
980
|
+
case 'compare':
|
|
981
|
+
case 'if':
|
|
982
|
+
case 'coalesce':
|
|
983
|
+
case 'call':
|
|
984
|
+
for (const arg of node.args)
|
|
985
|
+
visit(ctx, arg, findings);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
function checkLiteralRefusal(ctx, node) {
|
|
989
|
+
if (node.kind === 'call') {
|
|
990
|
+
if (node.op === '//' || node.op === '%' || node.op === '/') {
|
|
991
|
+
const divisor = node.args[1] === undefined ? undefined : constantOf(node.args[1]);
|
|
992
|
+
if (divisor !== undefined && isZero(divisor)) {
|
|
993
|
+
throw new ExpressionCompileError('INVALID_CONSTANT_EXPRESSION', ctx.offsetOf(node), `\`${node.op}\` divides by the literal zero, which no value can satisfy; supply a non-zero divisor or guard the call with \`f_count != 0\``);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
if (node.op === 'between') {
|
|
997
|
+
const low = node.args[1] === undefined ? undefined : constantOf(node.args[1]);
|
|
998
|
+
const high = node.args[2] === undefined ? undefined : constantOf(node.args[2]);
|
|
999
|
+
if (low !== undefined && high !== undefined) {
|
|
1000
|
+
const order = compareConstants(low, high);
|
|
1001
|
+
if (order !== undefined && order > 0) {
|
|
1002
|
+
throw new ExpressionCompileError('INVALID_CONSTANT_EXPRESSION', ctx.offsetOf(node), '`between(x, low, high)` states a low bound above its high bound, so no value can be in range; swap the bounds so `low <= high`');
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
if (node.op === 'ceil' || node.op === 'floor') {
|
|
1007
|
+
const operand = node.args[0] === undefined ? undefined : constantOf(node.args[0]);
|
|
1008
|
+
if (operand?.domain === 'decimal' && typeof operand.value === 'string') {
|
|
1009
|
+
try {
|
|
1010
|
+
if (node.op === 'ceil')
|
|
1011
|
+
ceilDecimal(asDecimalString(operand.value));
|
|
1012
|
+
else
|
|
1013
|
+
floorDecimal(asDecimalString(operand.value));
|
|
1014
|
+
}
|
|
1015
|
+
catch {
|
|
1016
|
+
throw new ExpressionCompileError('INVALID_CONSTANT_EXPRESSION', ctx.offsetOf(node), `\`${node.op}\` of this literal leaves the integer range -(2^53 - 1)..(2^53 - 1); keep the result inside the range`);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
if (node.op === '+' ||
|
|
1021
|
+
node.op === '-' ||
|
|
1022
|
+
node.op === '*' ||
|
|
1023
|
+
node.op === '//' ||
|
|
1024
|
+
node.op === '%' ||
|
|
1025
|
+
node.op === 'pow' ||
|
|
1026
|
+
node.op === 'abs') {
|
|
1027
|
+
const exact = exactInteger(node);
|
|
1028
|
+
if (exact !== undefined && !withinIntegerRange(exact)) {
|
|
1029
|
+
throw new ExpressionCompileError('INVALID_CONSTANT_EXPRESSION', ctx.offsetOf(node), `this integer operation evaluates to ${exact.toString()}, outside the integer range -(2^53 - 1)..(2^53 - 1); keep the result in range, or state the value as a \`decimal\` literal when it must exceed it`);
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
//# sourceMappingURL=lint.js.map
|