@typespec/compiler 0.67.0-dev.8 → 0.67.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/dist/generated-defs/TypeSpec.Prototypes.d.ts +1 -1
- package/dist/generated-defs/TypeSpec.Prototypes.d.ts.map +1 -1
- package/dist/generated-defs/TypeSpec.d.ts +29 -2
- package/dist/generated-defs/TypeSpec.d.ts.map +1 -1
- package/dist/manifest.js +2 -2
- package/dist/src/ast/index.d.ts +14 -0
- package/dist/src/ast/index.d.ts.map +1 -0
- package/dist/src/ast/index.js +13 -0
- package/dist/src/ast/index.js.map +1 -0
- package/dist/src/config/config-loader.d.ts.map +1 -1
- package/dist/src/config/config-loader.js +2 -1
- package/dist/src/config/config-loader.js.map +1 -1
- package/dist/src/config/config-to-options.d.ts.map +1 -1
- package/dist/src/config/config-to-options.js +4 -2
- package/dist/src/config/config-to-options.js.map +1 -1
- package/dist/src/config/types.d.ts +1 -1
- package/dist/src/core/binder.d.ts.map +1 -1
- package/dist/src/core/binder.js +18 -137
- package/dist/src/core/binder.js.map +1 -1
- package/dist/src/core/checker.d.ts +7 -23
- package/dist/src/core/checker.d.ts.map +1 -1
- package/dist/src/core/checker.js +59 -780
- package/dist/src/core/checker.js.map +1 -1
- package/dist/src/core/cli/actions/compile/args.d.ts +1 -0
- package/dist/src/core/cli/actions/compile/args.d.ts.map +1 -1
- package/dist/src/core/cli/actions/compile/args.js +3 -0
- package/dist/src/core/cli/actions/compile/args.js.map +1 -1
- package/dist/src/core/cli/actions/compile/compile.js +1 -1
- package/dist/src/core/cli/actions/compile/compile.js.map +1 -1
- package/dist/src/core/cli/cli.js +14 -4
- package/dist/src/core/cli/cli.js.map +1 -1
- package/dist/src/core/cli/utils.d.ts.map +1 -1
- package/dist/src/core/cli/utils.js +5 -1
- package/dist/src/core/cli/utils.js.map +1 -1
- package/dist/src/core/decorator-utils.d.ts.map +1 -1
- package/dist/src/core/decorator-utils.js +1 -3
- package/dist/src/core/decorator-utils.js.map +1 -1
- package/dist/src/core/diagnostic-error.d.ts +7 -0
- package/dist/src/core/diagnostic-error.d.ts.map +1 -0
- package/dist/src/core/diagnostic-error.js +9 -0
- package/dist/src/core/diagnostic-error.js.map +1 -0
- package/dist/src/core/diagnostics.d.ts +6 -6
- package/dist/src/core/diagnostics.d.ts.map +1 -1
- package/dist/src/core/diagnostics.js +10 -11
- package/dist/src/core/diagnostics.js.map +1 -1
- package/dist/src/core/emitter-utils.js +2 -2
- package/dist/src/core/emitter-utils.js.map +1 -1
- package/dist/src/core/entrypoint-resolution.d.ts.map +1 -1
- package/dist/src/core/entrypoint-resolution.js +2 -1
- package/dist/src/core/entrypoint-resolution.js.map +1 -1
- package/dist/src/core/helpers/discriminator-utils.d.ts +1 -6
- package/dist/src/core/helpers/discriminator-utils.d.ts.map +1 -1
- package/dist/src/core/helpers/discriminator-utils.js +1 -57
- package/dist/src/core/helpers/discriminator-utils.js.map +1 -1
- package/dist/src/core/helpers/index.d.ts +5 -6
- package/dist/src/core/helpers/index.d.ts.map +1 -1
- package/dist/src/core/helpers/index.js +5 -6
- package/dist/src/core/helpers/index.js.map +1 -1
- package/dist/src/core/helpers/syntax-utils.d.ts +2 -1
- package/dist/src/core/helpers/syntax-utils.d.ts.map +1 -1
- package/dist/src/core/helpers/syntax-utils.js +8 -4
- package/dist/src/core/helpers/syntax-utils.js.map +1 -1
- package/dist/src/core/index.d.ts +1 -26
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +1 -26
- package/dist/src/core/index.js.map +1 -1
- package/dist/src/core/inspector/symbol.d.ts.map +1 -1
- package/dist/src/core/inspector/symbol.js +9 -11
- package/dist/src/core/inspector/symbol.js.map +1 -1
- package/dist/src/core/intrinsic-type-state.d.ts +1 -1
- package/dist/src/core/intrinsic-type-state.d.ts.map +1 -1
- package/dist/src/core/js-marshaller.d.ts +0 -9
- package/dist/src/core/js-marshaller.d.ts.map +1 -1
- package/dist/src/core/js-marshaller.js +0 -26
- package/dist/src/core/js-marshaller.js.map +1 -1
- package/dist/src/core/logger/console-sink.browser.d.ts.map +1 -1
- package/dist/src/core/logger/console-sink.browser.js +0 -16
- package/dist/src/core/logger/console-sink.browser.js.map +1 -1
- package/dist/src/core/logger/console-sink.d.ts +2 -3
- package/dist/src/core/logger/console-sink.d.ts.map +1 -1
- package/dist/src/core/logger/console-sink.js +16 -43
- package/dist/src/core/logger/console-sink.js.map +1 -1
- package/dist/src/core/logger/dynamic-task.d.ts +16 -0
- package/dist/src/core/logger/dynamic-task.d.ts.map +1 -0
- package/dist/src/core/logger/dynamic-task.js +93 -0
- package/dist/src/core/logger/dynamic-task.js.map +1 -0
- package/dist/src/core/logger/logger.d.ts.map +1 -1
- package/dist/src/core/logger/logger.js +11 -1
- package/dist/src/core/logger/logger.js.map +1 -1
- package/dist/src/core/messages.d.ts +35 -45
- package/dist/src/core/messages.d.ts.map +1 -1
- package/dist/src/core/messages.js +9 -11
- package/dist/src/core/messages.js.map +1 -1
- package/dist/src/core/name-resolver.d.ts.map +1 -1
- package/dist/src/core/name-resolver.js +12 -23
- package/dist/src/core/name-resolver.js.map +1 -1
- package/dist/src/core/node-host.d.ts +0 -3
- package/dist/src/core/node-host.d.ts.map +1 -1
- package/dist/src/core/node-host.js +5 -51
- package/dist/src/core/node-host.js.map +1 -1
- package/dist/src/core/node-system-host.d.ts +9 -0
- package/dist/src/core/node-system-host.d.ts.map +1 -0
- package/dist/src/core/node-system-host.js +57 -0
- package/dist/src/core/node-system-host.js.map +1 -0
- package/dist/src/core/options.d.ts +9 -0
- package/dist/src/core/options.d.ts.map +1 -1
- package/dist/src/core/parser.d.ts.map +1 -1
- package/dist/src/core/parser.js +50 -654
- package/dist/src/core/parser.js.map +1 -1
- package/dist/src/core/program.d.ts +6 -16
- package/dist/src/core/program.d.ts.map +1 -1
- package/dist/src/core/program.js +48 -24
- package/dist/src/core/program.js.map +1 -1
- package/dist/src/core/scanner.d.ts +37 -1
- package/dist/src/core/scanner.d.ts.map +1 -1
- package/dist/src/core/scanner.js +150 -3
- package/dist/src/core/scanner.js.map +1 -1
- package/dist/src/core/semantic-walker.d.ts.map +1 -1
- package/dist/src/core/semantic-walker.js +0 -9
- package/dist/src/core/semantic-walker.js.map +1 -1
- package/dist/src/core/source-loader.d.ts.map +1 -1
- package/dist/src/core/source-loader.js +2 -1
- package/dist/src/core/source-loader.js.map +1 -1
- package/dist/src/core/state-accessors.d.ts +53 -12
- package/dist/src/core/state-accessors.d.ts.map +1 -1
- package/dist/src/core/state-accessors.js +75 -48
- package/dist/src/core/state-accessors.js.map +1 -1
- package/dist/src/core/type-relation-checker.d.ts.map +1 -1
- package/dist/src/core/type-relation-checker.js +4 -22
- package/dist/src/core/type-relation-checker.js.map +1 -1
- package/dist/src/core/type-utils.js +2 -2
- package/dist/src/core/type-utils.js.map +1 -1
- package/dist/src/core/types.d.ts +58 -324
- package/dist/src/core/types.d.ts.map +1 -1
- package/dist/src/core/types.js +24 -55
- package/dist/src/core/types.js.map +1 -1
- package/dist/src/core/visibility/lifecycle.d.ts.map +1 -1
- package/dist/src/core/visibility/lifecycle.js +2 -11
- package/dist/src/core/visibility/lifecycle.js.map +1 -1
- package/dist/src/emitter-framework/asset-emitter.d.ts +2 -1
- package/dist/src/emitter-framework/asset-emitter.d.ts.map +1 -1
- package/dist/src/emitter-framework/asset-emitter.js +2 -2
- package/dist/src/emitter-framework/asset-emitter.js.map +1 -1
- package/dist/src/emitter-framework/builders/array-builder.js +1 -1
- package/dist/src/emitter-framework/builders/array-builder.js.map +1 -1
- package/dist/src/emitter-framework/builders/object-builder.js +1 -1
- package/dist/src/emitter-framework/builders/object-builder.js.map +1 -1
- package/dist/src/emitter-framework/index.d.ts +74 -8
- package/dist/src/emitter-framework/index.d.ts.map +1 -1
- package/dist/src/emitter-framework/index.js +32 -8
- package/dist/src/emitter-framework/index.js.map +1 -1
- package/dist/src/emitter-framework/reference-cycle.d.ts +1 -1
- package/dist/src/emitter-framework/types.d.ts +2 -1
- package/dist/src/emitter-framework/types.d.ts.map +1 -1
- package/dist/src/experimental/freeze-graph.d.ts +1 -1
- package/dist/src/experimental/freeze-graph.d.ts.map +1 -1
- package/dist/src/experimental/freeze-graph.js +1 -4
- package/dist/src/experimental/freeze-graph.js.map +1 -1
- package/dist/src/experimental/mutators.d.ts +2 -2
- package/dist/src/experimental/mutators.d.ts.map +1 -1
- package/dist/src/experimental/mutators.js +3 -8
- package/dist/src/experimental/mutators.js.map +1 -1
- package/dist/src/experimental/typekit/index.d.ts +1 -1
- package/dist/src/experimental/typekit/index.d.ts.map +1 -1
- package/dist/src/experimental/typekit/index.js +1 -1
- package/dist/src/experimental/typekit/index.js.map +1 -1
- package/dist/src/experimental/typekit/kits/model.d.ts +6 -0
- package/dist/src/experimental/typekit/kits/model.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/model.js +10 -0
- package/dist/src/experimental/typekit/kits/model.js.map +1 -1
- package/dist/src/experimental/typekit/kits/type.d.ts +0 -6
- package/dist/src/experimental/typekit/kits/type.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/type.js +16 -10
- package/dist/src/experimental/typekit/kits/type.js.map +1 -1
- package/dist/src/experimental/typekit/kits/union.d.ts +6 -0
- package/dist/src/experimental/typekit/kits/union.d.ts.map +1 -1
- package/dist/src/experimental/typekit/kits/union.js +4 -0
- package/dist/src/experimental/typekit/kits/union.js.map +1 -1
- package/dist/src/formatter/print/comment-handler.js +1 -0
- package/dist/src/formatter/print/comment-handler.js.map +1 -1
- package/dist/src/formatter/print/needs-parens.d.ts.map +1 -1
- package/dist/src/formatter/print/needs-parens.js +0 -4
- package/dist/src/formatter/print/needs-parens.js.map +1 -1
- package/dist/src/formatter/print/printer.d.ts +4 -12
- package/dist/src/formatter/print/printer.d.ts.map +1 -1
- package/dist/src/formatter/print/printer.js +14 -196
- package/dist/src/formatter/print/printer.js.map +1 -1
- package/dist/src/index.d.ts +27 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +32 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/init/core-templates.d.ts +2 -2
- package/dist/src/init/core-templates.d.ts.map +1 -1
- package/dist/src/init/core-templates.js.map +1 -1
- package/dist/src/init/init.d.ts +0 -2
- package/dist/src/init/init.d.ts.map +1 -1
- package/dist/src/init/init.js +17 -51
- package/dist/src/init/init.js.map +1 -1
- package/dist/src/init/scaffold.d.ts +4 -3
- package/dist/src/init/scaffold.d.ts.map +1 -1
- package/dist/src/init/scaffold.js +3 -4
- package/dist/src/init/scaffold.js.map +1 -1
- package/dist/src/install/config.d.ts +9 -0
- package/dist/src/install/config.d.ts.map +1 -0
- package/dist/src/install/config.js +16 -0
- package/dist/src/install/config.js.map +1 -0
- package/dist/src/install/install.d.ts +14 -0
- package/dist/src/install/install.d.ts.map +1 -0
- package/dist/src/install/install.js +191 -0
- package/dist/src/install/install.js.map +1 -0
- package/dist/src/install/spec.d.ts +39 -0
- package/dist/src/install/spec.d.ts.map +1 -0
- package/dist/src/install/spec.js +152 -0
- package/dist/src/install/spec.js.map +1 -0
- package/dist/src/internals/index.d.ts +8 -0
- package/dist/src/internals/index.d.ts.map +1 -0
- package/dist/src/internals/index.js +11 -0
- package/dist/src/internals/index.js.map +1 -0
- package/dist/src/lib/decorators.d.ts +16 -4
- package/dist/src/lib/decorators.d.ts.map +1 -1
- package/dist/src/lib/decorators.js +89 -46
- package/dist/src/lib/decorators.js.map +1 -1
- package/dist/src/lib/examples.js +1 -5
- package/dist/src/lib/examples.js.map +1 -1
- package/dist/src/lib/key.d.ts +1 -1
- package/dist/src/lib/key.d.ts.map +1 -1
- package/dist/src/lib/paging.d.ts +1 -1
- package/dist/src/lib/paging.d.ts.map +1 -1
- package/dist/src/lib/paging.js +3 -1
- package/dist/src/lib/paging.js.map +1 -1
- package/dist/src/lib/service.d.ts.map +1 -1
- package/dist/src/lib/service.js +0 -4
- package/dist/src/lib/service.js.map +1 -1
- package/dist/src/lib/tsp-index.d.ts.map +1 -1
- package/dist/src/lib/tsp-index.js +2 -2
- package/dist/src/lib/tsp-index.js.map +1 -1
- package/dist/src/lib/visibility.js +1 -1
- package/dist/src/lib/visibility.js.map +1 -1
- package/dist/src/module-resolver/module-resolver.d.ts.map +1 -1
- package/dist/src/module-resolver/module-resolver.js +20 -13
- package/dist/src/module-resolver/module-resolver.js.map +1 -1
- package/dist/src/package-manger/npm-registry-utils.d.ts +83 -0
- package/dist/src/package-manger/npm-registry-utils.d.ts.map +1 -0
- package/dist/src/package-manger/npm-registry-utils.js +42 -0
- package/dist/src/package-manger/npm-registry-utils.js.map +1 -0
- package/dist/src/server/classify.d.ts +1 -1
- package/dist/src/server/classify.d.ts.map +1 -1
- package/dist/src/server/classify.js +4 -27
- package/dist/src/server/classify.js.map +1 -1
- package/dist/src/server/compile-service.d.ts +1 -1
- package/dist/src/server/compile-service.d.ts.map +1 -1
- package/dist/src/server/compile-service.js +5 -2
- package/dist/src/server/compile-service.js.map +1 -1
- package/dist/src/server/completion.d.ts +2 -1
- package/dist/src/server/completion.d.ts.map +1 -1
- package/dist/src/server/completion.js +24 -10
- package/dist/src/server/completion.js.map +1 -1
- package/dist/src/server/constants.d.ts +1 -1
- package/dist/src/server/constants.d.ts.map +1 -1
- package/dist/src/server/constants.js +1 -1
- package/dist/src/server/index.d.ts +2 -2
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +1 -2
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/server.js +1 -1
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/serverlib.d.ts.map +1 -1
- package/dist/src/server/serverlib.js +3 -2
- package/dist/src/server/serverlib.js.map +1 -1
- package/dist/src/server/symbol-structure.d.ts +1 -1
- package/dist/src/server/symbol-structure.d.ts.map +1 -1
- package/dist/src/server/tmlanguage.d.ts.map +1 -1
- package/dist/src/server/tmlanguage.js +0 -125
- package/dist/src/server/tmlanguage.js.map +1 -1
- package/dist/src/server/type-details.js +4 -1
- package/dist/src/server/type-details.js.map +1 -1
- package/dist/src/server/type-signature.js +4 -15
- package/dist/src/server/type-signature.js.map +1 -1
- package/dist/src/server/types.d.ts +4 -2
- package/dist/src/server/types.d.ts.map +1 -1
- package/dist/src/server/types.js.map +1 -1
- package/dist/src/server/yaml-resolver.d.ts +1 -1
- package/dist/src/server/yaml-resolver.d.ts.map +1 -1
- package/dist/src/testing/code-fix-testing.d.ts +1 -1
- package/dist/src/testing/code-fix-testing.d.ts.map +1 -1
- package/dist/src/testing/code-fix-testing.js +3 -2
- package/dist/src/testing/code-fix-testing.js.map +1 -1
- package/dist/src/testing/expect.d.ts +1 -7
- package/dist/src/testing/expect.d.ts.map +1 -1
- package/dist/src/testing/expect.js +2 -13
- package/dist/src/testing/expect.js.map +1 -1
- package/dist/src/testing/index.d.ts +6 -6
- package/dist/src/testing/index.d.ts.map +1 -1
- package/dist/src/testing/index.js +5 -6
- package/dist/src/testing/index.js.map +1 -1
- package/dist/src/testing/rule-tester.d.ts +1 -1
- package/dist/src/testing/rule-tester.d.ts.map +1 -1
- package/dist/src/testing/rule-tester.js +2 -1
- package/dist/src/testing/rule-tester.js.map +1 -1
- package/dist/src/testing/source-utils.d.ts +20 -0
- package/dist/src/testing/source-utils.d.ts.map +1 -0
- package/dist/src/testing/source-utils.js +23 -0
- package/dist/src/testing/source-utils.js.map +1 -0
- package/dist/src/testing/test-host.d.ts.map +1 -1
- package/dist/src/testing/test-host.js +0 -4
- package/dist/src/testing/test-host.js.map +1 -1
- package/dist/src/testing/test-server-host.d.ts +0 -19
- package/dist/src/testing/test-server-host.d.ts.map +1 -1
- package/dist/src/testing/test-server-host.js +0 -22
- package/dist/src/testing/test-server-host.js.map +1 -1
- package/dist/src/testing/test-utils.d.ts +1 -1
- package/dist/src/testing/test-utils.d.ts.map +1 -1
- package/dist/src/testing/test-utils.js +4 -2
- package/dist/src/testing/test-utils.js.map +1 -1
- package/dist/src/testing/types.d.ts +3 -2
- package/dist/src/testing/types.d.ts.map +1 -1
- package/dist/src/testing/types.js.map +1 -1
- package/dist/src/types/package-json.d.ts +14 -0
- package/dist/src/types/package-json.d.ts.map +1 -1
- package/dist/src/utils/custom-key-map.d.ts.map +1 -0
- package/dist/src/utils/custom-key-map.js.map +1 -0
- package/dist/src/utils/fs-utils.d.ts +3 -0
- package/dist/src/utils/fs-utils.d.ts.map +1 -0
- package/dist/src/utils/fs-utils.js +19 -0
- package/dist/src/utils/fs-utils.js.map +1 -0
- package/dist/src/utils/io.d.ts +16 -0
- package/dist/src/utils/io.d.ts.map +1 -0
- package/dist/src/utils/io.js +77 -0
- package/dist/src/utils/io.js.map +1 -0
- package/dist/src/utils/misc.d.ts +4 -18
- package/dist/src/utils/misc.d.ts.map +1 -1
- package/dist/src/utils/misc.js +1 -77
- package/dist/src/utils/misc.js.map +1 -1
- package/dist/typespec.tmLanguage +0 -342
- package/lib/std/decorators.tsp +37 -2
- package/package.json +14 -7
- package/templates/__snapshots__/emitter-ts/src/emitter.ts +4 -6
- package/templates/emitter-ts/src/emitter.ts +4 -6
- package/templates/scaffolding.json +4 -4
- package/dist/src/core/helpers/projected-names-utils.d.ts +0 -20
- package/dist/src/core/helpers/projected-names-utils.d.ts.map +0 -1
- package/dist/src/core/helpers/projected-names-utils.js +0 -42
- package/dist/src/core/helpers/projected-names-utils.js.map +0 -1
- package/dist/src/core/install.d.ts +0 -3
- package/dist/src/core/install.d.ts.map +0 -1
- package/dist/src/core/install.js +0 -60
- package/dist/src/core/install.js.map +0 -1
- package/dist/src/core/projected-program.d.ts +0 -3
- package/dist/src/core/projected-program.d.ts.map +0 -1
- package/dist/src/core/projected-program.js +0 -4
- package/dist/src/core/projected-program.js.map +0 -1
- package/dist/src/core/projection-members.d.ts +0 -8
- package/dist/src/core/projection-members.d.ts.map +0 -1
- package/dist/src/core/projection-members.js +0 -382
- package/dist/src/core/projection-members.js.map +0 -1
- package/dist/src/core/projector.d.ts +0 -26
- package/dist/src/core/projector.d.ts.map +0 -1
- package/dist/src/core/projector.js +0 -572
- package/dist/src/core/projector.js.map +0 -1
- package/dist/src/emitter-framework/custom-key-map.d.ts.map +0 -1
- package/dist/src/emitter-framework/custom-key-map.js.map +0 -1
- /package/dist/src/{emitter-framework → utils}/custom-key-map.d.ts +0 -0
- /package/dist/src/{emitter-framework → utils}/custom-key-map.js +0 -0
package/dist/src/core/checker.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-deprecated */
|
|
2
1
|
import { Realm } from "../experimental/realm.js";
|
|
3
2
|
import { $ } from "../experimental/typekit/index.js";
|
|
4
3
|
import { docFromCommentDecorator, getIndexer } from "../lib/intrinsic/decorators.js";
|
|
@@ -8,17 +7,15 @@ import { createSymbol, getSymNode } from "./binder.js";
|
|
|
8
7
|
import { createChangeIdentifierCodeFix } from "./compiler-code-fixes/change-identifier.codefix.js";
|
|
9
8
|
import { createModelToObjectValueCodeFix, createTupleToArrayValueCodeFix, } from "./compiler-code-fixes/convert-to-value.codefix.js";
|
|
10
9
|
import { getDeprecationDetails, markDeprecated } from "./deprecation.js";
|
|
11
|
-
import {
|
|
10
|
+
import { compilerAssert, ignoreDiagnostics } from "./diagnostics.js";
|
|
12
11
|
import { validateInheritanceDiscriminatedUnions } from "./helpers/discriminator-utils.js";
|
|
13
|
-
import { getLocationContext } from "./helpers/location-context.js";
|
|
14
12
|
import { explainStringTemplateNotSerializable } from "./helpers/string-template-utils.js";
|
|
15
13
|
import { typeReferenceToString } from "./helpers/syntax-utils.js";
|
|
16
14
|
import { getEntityName, getTypeName } from "./helpers/type-name-utils.js";
|
|
17
|
-
import {
|
|
15
|
+
import { marshallTypeForJS } from "./js-marshaller.js";
|
|
18
16
|
import { createDiagnostic } from "./messages.js";
|
|
19
17
|
import { Numeric } from "./numeric.js";
|
|
20
18
|
import { exprIsBareIdentifier, getFirstAncestor, getIdentifierContext, hasParseError, visitChildren, } from "./parser.js";
|
|
21
|
-
import { createProjectionMembers } from "./projection-members.js";
|
|
22
19
|
import { createTypeRelationChecker } from "./type-relation-checker.js";
|
|
23
20
|
import { getFullyQualifiedSymbolName, getParentTemplateNode, isArrayModelType, isErrorType, isNullType, isTemplateInstance, isType, isValue, } from "./type-utils.js";
|
|
24
21
|
import { IdentifierKind, ResolutionResultFlags, SyntaxKind, } from "./types.js";
|
|
@@ -36,14 +33,7 @@ export function createChecker(program, resolver) {
|
|
|
36
33
|
let onCheckerDiagnostic = (x) => {
|
|
37
34
|
program.reportDiagnostic(x);
|
|
38
35
|
};
|
|
39
|
-
const typePrototype = {
|
|
40
|
-
get projections() {
|
|
41
|
-
return (projectionsByTypeKind.get(this.kind) || []).concat(projectionsByType.get(this) || []);
|
|
42
|
-
},
|
|
43
|
-
projectionsByName(name) {
|
|
44
|
-
return this.projections.filter((p) => p.id.sv === name);
|
|
45
|
-
},
|
|
46
|
-
};
|
|
36
|
+
const typePrototype = {};
|
|
47
37
|
const globalNamespaceType = createGlobalNamespaceType();
|
|
48
38
|
// Caches the deprecation test of nodes in the program
|
|
49
39
|
const nodeDeprecationMap = new Map();
|
|
@@ -52,23 +42,6 @@ export function createChecker(program, resolver) {
|
|
|
52
42
|
const neverType = createType({ kind: "Intrinsic", name: "never" });
|
|
53
43
|
const unknownType = createType({ kind: "Intrinsic", name: "unknown" });
|
|
54
44
|
const nullType = createType({ kind: "Intrinsic", name: "null" });
|
|
55
|
-
const projectionsByTypeKind = new Map([
|
|
56
|
-
["Model", []],
|
|
57
|
-
["ModelProperty", []],
|
|
58
|
-
["Scalar", []],
|
|
59
|
-
["Union", []],
|
|
60
|
-
["UnionVariant", []],
|
|
61
|
-
["Operation", []],
|
|
62
|
-
["Interface", []],
|
|
63
|
-
["Enum", []],
|
|
64
|
-
["EnumMember", []],
|
|
65
|
-
]);
|
|
66
|
-
const projectionsByType = new Map();
|
|
67
|
-
// whether we've checked this specific projection statement before
|
|
68
|
-
// and added it to the various projection maps.
|
|
69
|
-
const processedProjections = new Set();
|
|
70
|
-
// interpreter state
|
|
71
|
-
let currentProjectionDirection;
|
|
72
45
|
/**
|
|
73
46
|
* Set keeping track of node pending type resolution.
|
|
74
47
|
* Key is the SymId of a node. It can be retrieved with getNodeSymId(node)
|
|
@@ -78,7 +51,6 @@ export function createChecker(program, resolver) {
|
|
|
78
51
|
if (typespecNamespaceBinding) {
|
|
79
52
|
initializeTypeSpecIntrinsics();
|
|
80
53
|
}
|
|
81
|
-
let evalContext = undefined;
|
|
82
54
|
/**
|
|
83
55
|
* Tracking the template parameters used or not.
|
|
84
56
|
*/
|
|
@@ -92,8 +64,6 @@ export function createChecker(program, resolver) {
|
|
|
92
64
|
cloneType,
|
|
93
65
|
resolveRelatedSymbols,
|
|
94
66
|
resolveCompletions,
|
|
95
|
-
evalProjection,
|
|
96
|
-
project,
|
|
97
67
|
neverType,
|
|
98
68
|
errorType,
|
|
99
69
|
nullType,
|
|
@@ -102,7 +72,6 @@ export function createChecker(program, resolver) {
|
|
|
102
72
|
typePrototype,
|
|
103
73
|
createType,
|
|
104
74
|
createAndFinishType,
|
|
105
|
-
createFunctionType,
|
|
106
75
|
createLiteralType,
|
|
107
76
|
finishType,
|
|
108
77
|
isStdType,
|
|
@@ -116,7 +85,6 @@ export function createChecker(program, resolver) {
|
|
|
116
85
|
};
|
|
117
86
|
const relation = createTypeRelationChecker(program, checker);
|
|
118
87
|
checker.isTypeAssignableTo = relation.isTypeAssignableTo;
|
|
119
|
-
const projectionMembers = createProjectionMembers(checker);
|
|
120
88
|
return checker;
|
|
121
89
|
function getTemplateParameterUsageMap() {
|
|
122
90
|
return templateParameterUsageMap;
|
|
@@ -141,10 +109,10 @@ export function createChecker(program, resolver) {
|
|
|
141
109
|
function initializeTypeSpecIntrinsics() {
|
|
142
110
|
// a utility function to log strings or numbers
|
|
143
111
|
mutate(typespecNamespaceBinding.exports).set("log", {
|
|
144
|
-
flags:
|
|
112
|
+
flags: 2048 /* SymbolFlags.Function */,
|
|
145
113
|
name: "log",
|
|
146
114
|
value(p, ...strs) {
|
|
147
|
-
program.trace("
|
|
115
|
+
program.trace("log", strs.join(" "));
|
|
148
116
|
return voidType;
|
|
149
117
|
},
|
|
150
118
|
declarations: [],
|
|
@@ -276,9 +244,9 @@ export function createChecker(program, resolver) {
|
|
|
276
244
|
else {
|
|
277
245
|
entity = initial;
|
|
278
246
|
}
|
|
279
|
-
if (options.legacyTupleAndModelCast && entity !== null && isType(entity)) {
|
|
280
|
-
|
|
281
|
-
}
|
|
247
|
+
// if (options.legacyTupleAndModelCast && entity !== null && isType(entity)) {
|
|
248
|
+
// entity = legacy_tryTypeToValueCast(entity, constraint, node);
|
|
249
|
+
// }
|
|
282
250
|
if (entity === null) {
|
|
283
251
|
return null;
|
|
284
252
|
}
|
|
@@ -339,105 +307,48 @@ export function createChecker(program, resolver) {
|
|
|
339
307
|
return type;
|
|
340
308
|
}
|
|
341
309
|
}
|
|
342
|
-
|
|
310
|
+
/**
|
|
311
|
+
* Try to intercept types used as values, either return null and emit a diagnostic with a codefix or return the type as is to be dealt with the normal way.
|
|
312
|
+
*/
|
|
313
|
+
function interceptTypesUsedAsValue(type) {
|
|
343
314
|
switch (type.kind) {
|
|
344
315
|
case "Tuple":
|
|
345
|
-
return
|
|
316
|
+
return interceptTupleUsedAsValue(type);
|
|
346
317
|
case "Model":
|
|
347
|
-
return
|
|
318
|
+
return interceptModelExpressionUsedAsValue(type);
|
|
348
319
|
default:
|
|
349
320
|
return type;
|
|
350
321
|
}
|
|
351
322
|
}
|
|
352
323
|
// Legacy behavior to smooth transition to object values.
|
|
353
|
-
function
|
|
324
|
+
function interceptModelExpressionUsedAsValue(model) {
|
|
354
325
|
if (model.node?.kind !== SyntaxKind.ModelExpression) {
|
|
355
326
|
return model; // we only want to convert model expressions
|
|
356
327
|
}
|
|
357
328
|
reportCheckerDiagnostic(createDiagnostic({
|
|
358
|
-
code: "
|
|
329
|
+
code: "expect-value",
|
|
359
330
|
codefixes: [createModelToObjectValueCodeFix(model.node)],
|
|
360
|
-
|
|
361
|
-
message: "Using a model as a value is deprecated. Use an object value instead(with #{}).",
|
|
362
|
-
},
|
|
331
|
+
messageId: "modelExpression",
|
|
363
332
|
target: model.node,
|
|
364
333
|
}));
|
|
365
|
-
|
|
366
|
-
entityKind: "Value",
|
|
367
|
-
valueKind: "ObjectValue",
|
|
368
|
-
type: type ?? model,
|
|
369
|
-
node: model.node,
|
|
370
|
-
properties: new Map(),
|
|
371
|
-
};
|
|
372
|
-
for (const prop of model.properties.values()) {
|
|
373
|
-
let propValue = getValueFromIndeterminate(prop.type, { kind: "assignment", type: prop.type }, node);
|
|
374
|
-
if (propValue !== null && isType(propValue)) {
|
|
375
|
-
propValue = legacy_tryTypeToValueCast(propValue, { kind: "assignment", type: prop.type }, node);
|
|
376
|
-
}
|
|
377
|
-
if (propValue == null) {
|
|
378
|
-
return null;
|
|
379
|
-
}
|
|
380
|
-
else if (!isValue(propValue)) {
|
|
381
|
-
return model;
|
|
382
|
-
}
|
|
383
|
-
value.properties.set(prop.name, {
|
|
384
|
-
name: prop.name,
|
|
385
|
-
value: propValue,
|
|
386
|
-
node: prop.node,
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
if (type !== undefined && !checkTypeAssignable(model, type, node)) {
|
|
390
|
-
return null;
|
|
391
|
-
}
|
|
392
|
-
return value;
|
|
334
|
+
return null;
|
|
393
335
|
}
|
|
394
|
-
//
|
|
395
|
-
function
|
|
336
|
+
// Intercept tuple used as value and report diagnostic with a codefix
|
|
337
|
+
function interceptTupleUsedAsValue(tuple) {
|
|
396
338
|
if (tuple.node.kind !== SyntaxKind.TupleExpression) {
|
|
397
339
|
return tuple; // we won't convert dynamic tuples to array values
|
|
398
340
|
}
|
|
399
341
|
reportCheckerDiagnostic(createDiagnostic({
|
|
400
|
-
code: "
|
|
342
|
+
code: "expect-value",
|
|
401
343
|
codefixes: [createTupleToArrayValueCodeFix(tuple.node)],
|
|
402
|
-
|
|
403
|
-
message: "Using a tuple as a value is deprecated. Use an array value instead(with #[]).",
|
|
404
|
-
},
|
|
344
|
+
messageId: "tuple",
|
|
405
345
|
target: tuple.node,
|
|
406
346
|
}));
|
|
407
|
-
|
|
408
|
-
for (const [index, item] of tuple.values.entries()) {
|
|
409
|
-
const itemType = type?.kind === "Model" && isArrayModelType(program, type)
|
|
410
|
-
? type.indexer.value
|
|
411
|
-
: type?.kind === "Tuple"
|
|
412
|
-
? type.values[index]
|
|
413
|
-
: undefined;
|
|
414
|
-
let value = getValueFromIndeterminate(item, itemType && { kind: "assignment", type: itemType }, node);
|
|
415
|
-
if (value !== null && isType(value)) {
|
|
416
|
-
value = legacy_tryTypeToValueCast(value, itemType && { kind: "assignment", type: itemType }, node);
|
|
417
|
-
}
|
|
418
|
-
if (value === null) {
|
|
419
|
-
return null;
|
|
420
|
-
}
|
|
421
|
-
else if (!isValue(value)) {
|
|
422
|
-
return tuple;
|
|
423
|
-
}
|
|
424
|
-
values.push(value);
|
|
425
|
-
}
|
|
426
|
-
if (type !== undefined && !checkTypeAssignable(tuple, type, node)) {
|
|
427
|
-
return null;
|
|
428
|
-
}
|
|
429
|
-
return {
|
|
430
|
-
entityKind: "Value",
|
|
431
|
-
valueKind: "ArrayValue",
|
|
432
|
-
type: type ?? tuple,
|
|
433
|
-
node: tuple.node,
|
|
434
|
-
values,
|
|
435
|
-
};
|
|
347
|
+
return null;
|
|
436
348
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
ignoreDiagnostics(relation.isTypeAssignableTo(target, constraint.type, target))));
|
|
349
|
+
/** If the constraint only expect a value we can try to intercept types passed to it and call `interceptTypeUsedAsValue` to get a better error */
|
|
350
|
+
function shouldTryInterceptTypeUsedAsValue(constraint) {
|
|
351
|
+
return Boolean(constraint?.valueType && !constraint.type);
|
|
441
352
|
}
|
|
442
353
|
/**
|
|
443
354
|
* Gets a type or value depending on the node and current constraint.
|
|
@@ -451,8 +362,8 @@ export function createChecker(program, resolver) {
|
|
|
451
362
|
return entity;
|
|
452
363
|
}
|
|
453
364
|
else if (isType(entity)) {
|
|
454
|
-
if (
|
|
455
|
-
return
|
|
365
|
+
if (shouldTryInterceptTypeUsedAsValue(constraint?.constraint)) {
|
|
366
|
+
return interceptTypesUsedAsValue(entity);
|
|
456
367
|
}
|
|
457
368
|
else {
|
|
458
369
|
return entity;
|
|
@@ -543,8 +454,6 @@ export function createChecker(program, resolver) {
|
|
|
543
454
|
return checkTemplateArgument(node, mapper);
|
|
544
455
|
case SyntaxKind.TemplateParameterDeclaration:
|
|
545
456
|
return checkTemplateParameterDeclaration(node, mapper);
|
|
546
|
-
case SyntaxKind.ProjectionStatement:
|
|
547
|
-
return checkProjectionDeclaration(node);
|
|
548
457
|
case SyntaxKind.VoidKeyword:
|
|
549
458
|
return voidType;
|
|
550
459
|
case SyntaxKind.NeverKeyword:
|
|
@@ -583,9 +492,7 @@ export function createChecker(program, resolver) {
|
|
|
583
492
|
* Check if the given namespace is the standard library `TypeSpec` namespace.
|
|
584
493
|
*/
|
|
585
494
|
function isTypeSpecNamespace(namespace) {
|
|
586
|
-
return
|
|
587
|
-
(namespace.namespace === globalNamespaceType ||
|
|
588
|
-
namespace.namespace?.projectionBase === globalNamespaceType));
|
|
495
|
+
return namespace.name === "TypeSpec" && namespace.namespace === globalNamespaceType;
|
|
589
496
|
}
|
|
590
497
|
/**
|
|
591
498
|
* Check if the given type is defined right in the TypeSpec namespace.
|
|
@@ -873,8 +780,8 @@ export function createChecker(program, resolver) {
|
|
|
873
780
|
const constraint = param.constraint.type?.kind === "TemplateParameter"
|
|
874
781
|
? finalMap.get(param.constraint.type)
|
|
875
782
|
: param.constraint;
|
|
876
|
-
if (isType(type) &&
|
|
877
|
-
const converted =
|
|
783
|
+
if (isType(type) && shouldTryInterceptTypeUsedAsValue(param.constraint)) {
|
|
784
|
+
const converted = interceptTypesUsedAsValue(type);
|
|
878
785
|
// If we manage to convert it means this might be convertable so we skip type checking.
|
|
879
786
|
// However we still return the original entity
|
|
880
787
|
if (converted !== type) {
|
|
@@ -934,14 +841,14 @@ export function createChecker(program, resolver) {
|
|
|
934
841
|
return entity;
|
|
935
842
|
}
|
|
936
843
|
function checkTypeOrValueReferenceSymbolWorker(sym, node, mapper, instantiateTemplates = true) {
|
|
937
|
-
if (sym.flags &
|
|
844
|
+
if (sym.flags & 131072 /* SymbolFlags.Const */) {
|
|
938
845
|
return getValueForNode(sym.declarations[0], mapper);
|
|
939
846
|
}
|
|
940
|
-
if (sym.flags &
|
|
847
|
+
if (sym.flags & 512 /* SymbolFlags.Decorator */) {
|
|
941
848
|
reportCheckerDiagnostic(createDiagnostic({ code: "invalid-type-ref", messageId: "decorator", target: sym }));
|
|
942
849
|
return errorType;
|
|
943
850
|
}
|
|
944
|
-
if (sym.flags &
|
|
851
|
+
if (sym.flags & 2048 /* SymbolFlags.Function */) {
|
|
945
852
|
reportCheckerDiagnostic(createDiagnostic({ code: "invalid-type-ref", messageId: "function", target: sym }));
|
|
946
853
|
return errorType;
|
|
947
854
|
}
|
|
@@ -972,7 +879,7 @@ export function createChecker(program, resolver) {
|
|
|
972
879
|
else if (symbolLinks.declaredType) {
|
|
973
880
|
baseType = symbolLinks.declaredType;
|
|
974
881
|
}
|
|
975
|
-
else if (sym.flags &
|
|
882
|
+
else if (sym.flags & 65536 /* SymbolFlags.Member */) {
|
|
976
883
|
baseType = checkMemberSym(sym, mapper);
|
|
977
884
|
}
|
|
978
885
|
else {
|
|
@@ -1000,7 +907,7 @@ export function createChecker(program, resolver) {
|
|
|
1000
907
|
compilerAssert(sym.type, `Expected late bound symbol to have type`);
|
|
1001
908
|
return sym.type;
|
|
1002
909
|
}
|
|
1003
|
-
else if (sym.flags &
|
|
910
|
+
else if (sym.flags & 1024 /* SymbolFlags.TemplateParameter */) {
|
|
1004
911
|
const mapped = checkTemplateParameterDeclaration(symNode, mapper);
|
|
1005
912
|
baseType = mapped;
|
|
1006
913
|
}
|
|
@@ -1012,7 +919,7 @@ export function createChecker(program, resolver) {
|
|
|
1012
919
|
baseType = symbolLinks.declaredType;
|
|
1013
920
|
}
|
|
1014
921
|
else {
|
|
1015
|
-
if (sym.flags &
|
|
922
|
+
if (sym.flags & 65536 /* SymbolFlags.Member */) {
|
|
1016
923
|
baseType = checkMemberSym(sym, mapper);
|
|
1017
924
|
}
|
|
1018
925
|
else {
|
|
@@ -1054,7 +961,7 @@ export function createChecker(program, resolver) {
|
|
|
1054
961
|
compilerAssert(sym.type, "Expected late bound symbol to have type");
|
|
1055
962
|
return sym.type;
|
|
1056
963
|
}
|
|
1057
|
-
if (sym.flags &
|
|
964
|
+
if (sym.flags & 65536 /* SymbolFlags.Member */) {
|
|
1058
965
|
return checkMemberSym(sym, mapper);
|
|
1059
966
|
}
|
|
1060
967
|
else {
|
|
@@ -1266,34 +1173,8 @@ export function createChecker(program, resolver) {
|
|
|
1266
1173
|
return decoratorType;
|
|
1267
1174
|
}
|
|
1268
1175
|
function checkFunctionDeclaration(node, mapper) {
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
if (links.declaredType && mapper === undefined) {
|
|
1272
|
-
// we're not instantiating this operation and we've already checked it
|
|
1273
|
-
return links.declaredType;
|
|
1274
|
-
}
|
|
1275
|
-
const namespace = getParentNamespaceType(node);
|
|
1276
|
-
compilerAssert(namespace, `Decorator ${node.id.sv} should have resolved a namespace or found the global namespace.`);
|
|
1277
|
-
const name = node.id.sv;
|
|
1278
|
-
if (!(node.modifierFlags & 2 /* ModifierFlags.Extern */)) {
|
|
1279
|
-
reportCheckerDiagnostic(createDiagnostic({ code: "function-extern", target: node }));
|
|
1280
|
-
}
|
|
1281
|
-
const implementation = symbol.value;
|
|
1282
|
-
if (implementation === undefined) {
|
|
1283
|
-
reportCheckerDiagnostic(createDiagnostic({ code: "missing-implementation", target: node }));
|
|
1284
|
-
}
|
|
1285
|
-
const functionType = createType({
|
|
1286
|
-
kind: "Function",
|
|
1287
|
-
name,
|
|
1288
|
-
namespace,
|
|
1289
|
-
node,
|
|
1290
|
-
parameters: node.parameters.map((x) => checkFunctionParameter(x, mapper, true)),
|
|
1291
|
-
returnType: node.returnType ? getTypeForNode(node.returnType, mapper) : unknownType,
|
|
1292
|
-
implementation: implementation ?? (() => { }),
|
|
1293
|
-
});
|
|
1294
|
-
namespace.functionDeclarations.set(name, functionType);
|
|
1295
|
-
linkType(links, functionType, mapper);
|
|
1296
|
-
return functionType;
|
|
1176
|
+
reportCheckerDiagnostic(createDiagnostic({ code: "function-unsupported", target: node }));
|
|
1177
|
+
return errorType;
|
|
1297
1178
|
}
|
|
1298
1179
|
function checkFunctionParameter(node, mapper, mixed) {
|
|
1299
1180
|
const links = getSymbolLinks(node.symbol);
|
|
@@ -2118,10 +1999,10 @@ export function createChecker(program, resolver) {
|
|
|
2118
1999
|
}
|
|
2119
2000
|
table = resolver.getAugmentedSymbolTable(table);
|
|
2120
2001
|
for (const [key, sym] of table) {
|
|
2121
|
-
if (sym.flags &
|
|
2002
|
+
if (sym.flags & 16384 /* SymbolFlags.DuplicateUsing */) {
|
|
2122
2003
|
const duplicates = table.duplicates.get(sym);
|
|
2123
2004
|
for (const duplicate of duplicates) {
|
|
2124
|
-
if (duplicate.flags &
|
|
2005
|
+
if (duplicate.flags & 8192 /* SymbolFlags.Using */) {
|
|
2125
2006
|
const fqn = getFullyQualifiedSymbolName(duplicate.symbolSource);
|
|
2126
2007
|
addCompletion(fqn, duplicate);
|
|
2127
2008
|
}
|
|
@@ -2151,18 +2032,18 @@ export function createChecker(program, resolver) {
|
|
|
2151
2032
|
case IdentifierKind.ModelExpressionProperty:
|
|
2152
2033
|
case IdentifierKind.ModelStatementProperty:
|
|
2153
2034
|
case IdentifierKind.ObjectLiteralProperty:
|
|
2154
|
-
return !!(sym.flags &
|
|
2035
|
+
return !!(sym.flags & 65536 /* SymbolFlags.Member */);
|
|
2155
2036
|
case IdentifierKind.Decorator:
|
|
2156
2037
|
// Only return decorators and namespaces when completing decorator
|
|
2157
|
-
return !!(sym.flags & (
|
|
2038
|
+
return !!(sym.flags & (512 /* SymbolFlags.Decorator */ | 256 /* SymbolFlags.Namespace */));
|
|
2158
2039
|
case IdentifierKind.Using:
|
|
2159
2040
|
// Only return namespaces when completing using
|
|
2160
2041
|
return !!(sym.flags & 256 /* SymbolFlags.Namespace */);
|
|
2161
2042
|
case IdentifierKind.TypeReference:
|
|
2162
2043
|
// Do not return functions or decorators when completing types
|
|
2163
|
-
return !(sym.flags & (
|
|
2044
|
+
return !(sym.flags & (2048 /* SymbolFlags.Function */ | 512 /* SymbolFlags.Decorator */));
|
|
2164
2045
|
case IdentifierKind.TemplateArgument:
|
|
2165
|
-
return !!(sym.flags &
|
|
2046
|
+
return !!(sym.flags & 1024 /* SymbolFlags.TemplateParameter */);
|
|
2166
2047
|
default:
|
|
2167
2048
|
compilerAssert(false, "We should have bailed up-front on other kinds.");
|
|
2168
2049
|
}
|
|
@@ -2274,7 +2155,7 @@ export function createChecker(program, resolver) {
|
|
|
2274
2155
|
target: node,
|
|
2275
2156
|
}));
|
|
2276
2157
|
}
|
|
2277
|
-
else if (base.flags &
|
|
2158
|
+
else if (base.flags & 512 /* SymbolFlags.Decorator */) {
|
|
2278
2159
|
reportCheckerDiagnostic(createDiagnostic({
|
|
2279
2160
|
code: "invalid-ref",
|
|
2280
2161
|
messageId: "inDecorator",
|
|
@@ -2282,7 +2163,7 @@ export function createChecker(program, resolver) {
|
|
|
2282
2163
|
target: node,
|
|
2283
2164
|
}));
|
|
2284
2165
|
}
|
|
2285
|
-
else if (base.flags &
|
|
2166
|
+
else if (base.flags & 2048 /* SymbolFlags.Function */) {
|
|
2286
2167
|
reportCheckerDiagnostic(createDiagnostic({
|
|
2287
2168
|
code: "invalid-ref",
|
|
2288
2169
|
messageId: "node",
|
|
@@ -3301,27 +3182,27 @@ export function createChecker(program, resolver) {
|
|
|
3301
3182
|
switch (type.kind) {
|
|
3302
3183
|
case "Model":
|
|
3303
3184
|
for (const prop of walkPropertiesInherited(type)) {
|
|
3304
|
-
lateBindMember(prop,
|
|
3185
|
+
lateBindMember(prop, 65536 /* SymbolFlags.Member */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3305
3186
|
}
|
|
3306
3187
|
break;
|
|
3307
3188
|
case "Scalar":
|
|
3308
3189
|
for (const member of type.constructors.values()) {
|
|
3309
|
-
lateBindMember(member,
|
|
3190
|
+
lateBindMember(member, 65536 /* SymbolFlags.Member */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3310
3191
|
}
|
|
3311
3192
|
break;
|
|
3312
3193
|
case "Enum":
|
|
3313
3194
|
for (const member of type.members.values()) {
|
|
3314
|
-
lateBindMember(member,
|
|
3195
|
+
lateBindMember(member, 65536 /* SymbolFlags.Member */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3315
3196
|
}
|
|
3316
3197
|
break;
|
|
3317
3198
|
case "Interface":
|
|
3318
3199
|
for (const member of type.operations.values()) {
|
|
3319
|
-
lateBindMember(member,
|
|
3200
|
+
lateBindMember(member, 65536 /* SymbolFlags.Member */ | 8 /* SymbolFlags.Operation */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3320
3201
|
}
|
|
3321
3202
|
break;
|
|
3322
3203
|
case "Union":
|
|
3323
3204
|
for (const variant of type.variants.values()) {
|
|
3324
|
-
lateBindMember(variant,
|
|
3205
|
+
lateBindMember(variant, 65536 /* SymbolFlags.Member */ | 1048576 /* SymbolFlags.Declaration */);
|
|
3325
3206
|
}
|
|
3326
3207
|
break;
|
|
3327
3208
|
}
|
|
@@ -3567,7 +3448,7 @@ export function createChecker(program, resolver) {
|
|
|
3567
3448
|
// Error should already have been reported above
|
|
3568
3449
|
return undefined;
|
|
3569
3450
|
}
|
|
3570
|
-
if (!(sym.flags &
|
|
3451
|
+
if (!(sym.flags & 512 /* SymbolFlags.Decorator */)) {
|
|
3571
3452
|
reportCheckerDiagnostic(createDiagnostic({
|
|
3572
3453
|
code: "invalid-decorator",
|
|
3573
3454
|
format: { id: sym.name },
|
|
@@ -3600,22 +3481,6 @@ export function createChecker(program, resolver) {
|
|
|
3600
3481
|
args,
|
|
3601
3482
|
};
|
|
3602
3483
|
}
|
|
3603
|
-
function resolveDecoratorArgMarshalling(declaredType) {
|
|
3604
|
-
if (declaredType) {
|
|
3605
|
-
const location = getLocationContext(program, declaredType);
|
|
3606
|
-
if (location.type === "compiler") {
|
|
3607
|
-
return "new";
|
|
3608
|
-
}
|
|
3609
|
-
else if ((location.type === "library" || location.type === "project") &&
|
|
3610
|
-
location.flags?.decoratorArgMarshalling) {
|
|
3611
|
-
return location.flags.decoratorArgMarshalling;
|
|
3612
|
-
}
|
|
3613
|
-
else {
|
|
3614
|
-
return "new";
|
|
3615
|
-
}
|
|
3616
|
-
}
|
|
3617
|
-
return "new";
|
|
3618
|
-
}
|
|
3619
3484
|
/** Check the decorator target is valid */
|
|
3620
3485
|
function checkDecoratorTarget(targetType, declaration, decoratorNode) {
|
|
3621
3486
|
const [targetValid] = relation.isTypeAssignableTo(targetType, declaration.target.type, decoratorNode);
|
|
@@ -3681,7 +3546,6 @@ export function createChecker(program, resolver) {
|
|
|
3681
3546
|
}
|
|
3682
3547
|
}
|
|
3683
3548
|
const resolvedArgs = [];
|
|
3684
|
-
const jsMarshalling = resolveDecoratorArgMarshalling(declaration);
|
|
3685
3549
|
function resolveArg(argNode, perParamType) {
|
|
3686
3550
|
const arg = getTypeOrValueForNode(argNode, mapper, {
|
|
3687
3551
|
kind: "argument",
|
|
@@ -3696,7 +3560,7 @@ export function createChecker(program, resolver) {
|
|
|
3696
3560
|
jsValue: resolveDecoratorArgJsValue(arg, extractValueOfConstraints({
|
|
3697
3561
|
kind: "argument",
|
|
3698
3562
|
constraint: perParamType,
|
|
3699
|
-
})
|
|
3563
|
+
})),
|
|
3700
3564
|
};
|
|
3701
3565
|
}
|
|
3702
3566
|
else {
|
|
@@ -3765,12 +3629,10 @@ export function createChecker(program, resolver) {
|
|
|
3765
3629
|
function getIndexType(type) {
|
|
3766
3630
|
return type.kind === "Model" ? type.indexer?.value : undefined;
|
|
3767
3631
|
}
|
|
3768
|
-
function resolveDecoratorArgJsValue(value, valueConstraint
|
|
3632
|
+
function resolveDecoratorArgJsValue(value, valueConstraint) {
|
|
3769
3633
|
if (valueConstraint !== undefined) {
|
|
3770
3634
|
if (isValue(value)) {
|
|
3771
|
-
return
|
|
3772
|
-
? legacyMarshallTypeForJS(checker, value)
|
|
3773
|
-
: marshallTypeForJS(value, valueConstraint.type);
|
|
3635
|
+
return marshallTypeForJS(value, valueConstraint.type);
|
|
3774
3636
|
}
|
|
3775
3637
|
else {
|
|
3776
3638
|
return value;
|
|
@@ -3819,7 +3681,7 @@ export function createChecker(program, resolver) {
|
|
|
3819
3681
|
}
|
|
3820
3682
|
else if (links.finalSymbol?.flags &&
|
|
3821
3683
|
~links.finalSymbol.flags & 1048576 /* SymbolFlags.Declaration */ &&
|
|
3822
|
-
~links.finalSymbol.flags &
|
|
3684
|
+
~links.finalSymbol.flags & 65536 /* SymbolFlags.Member */) {
|
|
3823
3685
|
program.reportDiagnostic(createDiagnostic({
|
|
3824
3686
|
code: "augment-decorator-target",
|
|
3825
3687
|
messageId: links.finalSymbol.flags & 2 /* SymbolFlags.Model */
|
|
@@ -4269,7 +4131,7 @@ export function createChecker(program, resolver) {
|
|
|
4269
4131
|
return variantType;
|
|
4270
4132
|
}
|
|
4271
4133
|
function isMemberNode(node) {
|
|
4272
|
-
return node.symbol && !!(node.symbol.flags &
|
|
4134
|
+
return node.symbol && !!(node.symbol.flags & 65536 /* SymbolFlags.Member */);
|
|
4273
4135
|
}
|
|
4274
4136
|
function getMemberSymbol(parentSym, name) {
|
|
4275
4137
|
return parentSym ? resolver.getAugmentedSymbolTable(parentSym.members).get(name) : undefined;
|
|
@@ -4383,8 +4245,6 @@ export function createChecker(program, resolver) {
|
|
|
4383
4245
|
}
|
|
4384
4246
|
/**
|
|
4385
4247
|
* Given the own-properties of a type, returns a fully-initialized type.
|
|
4386
|
-
* So far, that amounts to setting the prototype to typePrototype which
|
|
4387
|
-
* contains the `projections` getter.
|
|
4388
4248
|
*/
|
|
4389
4249
|
function createType(typeDef) {
|
|
4390
4250
|
Object.setPrototypeOf(typeDef, typePrototype);
|
|
@@ -4526,10 +4386,6 @@ export function createChecker(program, resolver) {
|
|
|
4526
4386
|
if (type.isFinished) {
|
|
4527
4387
|
clone = finishType(clone);
|
|
4528
4388
|
}
|
|
4529
|
-
const projection = projectionsByType.get(type);
|
|
4530
|
-
if (projection) {
|
|
4531
|
-
projectionsByType.set(clone, projection);
|
|
4532
|
-
}
|
|
4533
4389
|
compilerAssert(clone.kind === type.kind, "cloneType must not change type kind");
|
|
4534
4390
|
return clone;
|
|
4535
4391
|
}
|
|
@@ -4557,472 +4413,6 @@ export function createChecker(program, resolver) {
|
|
|
4557
4413
|
compilerAssert(clone.kind === type.kind, "cloneType must not change type kind");
|
|
4558
4414
|
return clone;
|
|
4559
4415
|
}
|
|
4560
|
-
function checkProjectionDeclaration(node) {
|
|
4561
|
-
// todo: check for duplicate projection decls on individual types
|
|
4562
|
-
// right now you can declare the same projection on a specific type
|
|
4563
|
-
// this could maybe go in the binder? But right now we don't know
|
|
4564
|
-
// what an identifier resolves to until check time.
|
|
4565
|
-
const links = getSymbolLinks(node.symbol);
|
|
4566
|
-
if (processedProjections.has(node)) {
|
|
4567
|
-
return links.declaredType;
|
|
4568
|
-
}
|
|
4569
|
-
processedProjections.add(node);
|
|
4570
|
-
reportCheckerDiagnostic(createDiagnostic({
|
|
4571
|
-
code: "deprecated",
|
|
4572
|
-
format: { message: "Projection are deprecated and will be removed in next version" },
|
|
4573
|
-
target: node,
|
|
4574
|
-
}));
|
|
4575
|
-
let type;
|
|
4576
|
-
if (links.declaredType) {
|
|
4577
|
-
type = links.declaredType;
|
|
4578
|
-
}
|
|
4579
|
-
else {
|
|
4580
|
-
type = links.declaredType = createType({
|
|
4581
|
-
kind: "Projection",
|
|
4582
|
-
node: undefined,
|
|
4583
|
-
nodeByKind: new Map(),
|
|
4584
|
-
nodeByType: new Map(),
|
|
4585
|
-
});
|
|
4586
|
-
}
|
|
4587
|
-
switch (node.selector.kind) {
|
|
4588
|
-
case SyntaxKind.ProjectionModelSelector:
|
|
4589
|
-
projectionsByTypeKind.get("Model").push(node);
|
|
4590
|
-
type.nodeByKind.set("Model", node);
|
|
4591
|
-
break;
|
|
4592
|
-
case SyntaxKind.ProjectionModelPropertySelector:
|
|
4593
|
-
projectionsByTypeKind.get("ModelProperty").push(node);
|
|
4594
|
-
type.nodeByKind.set("ModelProperty", node);
|
|
4595
|
-
break;
|
|
4596
|
-
case SyntaxKind.ProjectionScalarSelector:
|
|
4597
|
-
projectionsByTypeKind.get("Scalar").push(node);
|
|
4598
|
-
type.nodeByKind.set("Scalar", node);
|
|
4599
|
-
break;
|
|
4600
|
-
case SyntaxKind.ProjectionOperationSelector:
|
|
4601
|
-
projectionsByTypeKind.get("Operation").push(node);
|
|
4602
|
-
type.nodeByKind.set("Operation", node);
|
|
4603
|
-
break;
|
|
4604
|
-
case SyntaxKind.ProjectionUnionSelector:
|
|
4605
|
-
projectionsByTypeKind.get("Union").push(node);
|
|
4606
|
-
type.nodeByKind.set("Union", node);
|
|
4607
|
-
break;
|
|
4608
|
-
case SyntaxKind.ProjectionUnionVariantSelector:
|
|
4609
|
-
projectionsByTypeKind.get("UnionVariant").push(node);
|
|
4610
|
-
type.nodeByKind.set("UnionVariant", node);
|
|
4611
|
-
break;
|
|
4612
|
-
case SyntaxKind.ProjectionInterfaceSelector:
|
|
4613
|
-
projectionsByTypeKind.get("Interface").push(node);
|
|
4614
|
-
type.nodeByKind.set("Interface", node);
|
|
4615
|
-
break;
|
|
4616
|
-
case SyntaxKind.ProjectionEnumSelector:
|
|
4617
|
-
projectionsByTypeKind.get("Enum").push(node);
|
|
4618
|
-
type.nodeByKind.set("Enum", node);
|
|
4619
|
-
break;
|
|
4620
|
-
case SyntaxKind.ProjectionEnumMemberSelector:
|
|
4621
|
-
projectionsByTypeKind.get("EnumMember").push(node);
|
|
4622
|
-
type.nodeByKind.set("EnumMember", node);
|
|
4623
|
-
break;
|
|
4624
|
-
default:
|
|
4625
|
-
const projected = checkTypeReference(node.selector, undefined);
|
|
4626
|
-
let current = projectionsByType.get(projected);
|
|
4627
|
-
if (!current) {
|
|
4628
|
-
current = [];
|
|
4629
|
-
projectionsByType.set(projected, current);
|
|
4630
|
-
}
|
|
4631
|
-
current.push(node);
|
|
4632
|
-
type.nodeByType.set(projected, node);
|
|
4633
|
-
break;
|
|
4634
|
-
}
|
|
4635
|
-
return type;
|
|
4636
|
-
}
|
|
4637
|
-
function evalProjectionNode(node) {
|
|
4638
|
-
switch (node.kind) {
|
|
4639
|
-
case SyntaxKind.ProjectionExpressionStatement:
|
|
4640
|
-
return evalProjectionExpressionStatement(node);
|
|
4641
|
-
case SyntaxKind.ProjectionCallExpression:
|
|
4642
|
-
return evalProjectionCallExpression(node);
|
|
4643
|
-
case SyntaxKind.ProjectionMemberExpression:
|
|
4644
|
-
return evalProjectionMemberExpression(node);
|
|
4645
|
-
case SyntaxKind.ProjectionDecoratorReferenceExpression:
|
|
4646
|
-
return evalProjectionDecoratorReference(node);
|
|
4647
|
-
case SyntaxKind.Identifier:
|
|
4648
|
-
return evalProjectionIdentifier(node);
|
|
4649
|
-
case SyntaxKind.ProjectionLambdaExpression:
|
|
4650
|
-
return evalProjectionLambdaExpression(node);
|
|
4651
|
-
case SyntaxKind.StringLiteral:
|
|
4652
|
-
return evalStringLiteral(node);
|
|
4653
|
-
case SyntaxKind.NumericLiteral:
|
|
4654
|
-
return evalNumericLiteral(node);
|
|
4655
|
-
case SyntaxKind.BooleanLiteral:
|
|
4656
|
-
return evalBooleanLiteral(node);
|
|
4657
|
-
case SyntaxKind.ProjectionBlockExpression:
|
|
4658
|
-
return evalProjectionBlockExpression(node);
|
|
4659
|
-
case SyntaxKind.ProjectionArithmeticExpression:
|
|
4660
|
-
return evalProjectionArithmeticExpression(node);
|
|
4661
|
-
case SyntaxKind.ProjectionIfExpression:
|
|
4662
|
-
return evalProjectionIfExpression(node);
|
|
4663
|
-
case SyntaxKind.ProjectionEqualityExpression:
|
|
4664
|
-
return evalProjectionEqualityExpression(node);
|
|
4665
|
-
case SyntaxKind.ProjectionUnaryExpression:
|
|
4666
|
-
return evalProjectionUnaryExpression(node);
|
|
4667
|
-
case SyntaxKind.ProjectionRelationalExpression:
|
|
4668
|
-
return evalProjectionRelationalExpression(node);
|
|
4669
|
-
case SyntaxKind.ProjectionModelExpression:
|
|
4670
|
-
return evalProjectionModelExpression(node);
|
|
4671
|
-
case SyntaxKind.VoidKeyword:
|
|
4672
|
-
return voidType;
|
|
4673
|
-
case SyntaxKind.NeverKeyword:
|
|
4674
|
-
return neverType;
|
|
4675
|
-
case SyntaxKind.UnknownKeyword:
|
|
4676
|
-
return unknownType;
|
|
4677
|
-
case SyntaxKind.Return:
|
|
4678
|
-
return evalReturnKeyword(node);
|
|
4679
|
-
default:
|
|
4680
|
-
compilerAssert(false, `Can't eval the node ${SyntaxKind[node.kind]}`);
|
|
4681
|
-
}
|
|
4682
|
-
}
|
|
4683
|
-
function evalReturnKeyword(node) {
|
|
4684
|
-
const value = evalProjectionNode(node.value);
|
|
4685
|
-
if (value.kind === "Return") {
|
|
4686
|
-
return value;
|
|
4687
|
-
}
|
|
4688
|
-
return {
|
|
4689
|
-
kind: "Return",
|
|
4690
|
-
value,
|
|
4691
|
-
};
|
|
4692
|
-
}
|
|
4693
|
-
function evalProjectionModelExpression(node) {
|
|
4694
|
-
const modelType = createType({
|
|
4695
|
-
kind: "Model",
|
|
4696
|
-
name: "",
|
|
4697
|
-
node: node,
|
|
4698
|
-
decorators: [],
|
|
4699
|
-
properties: createRekeyableMap(),
|
|
4700
|
-
derivedModels: [],
|
|
4701
|
-
sourceModels: [],
|
|
4702
|
-
});
|
|
4703
|
-
for (const propNode of node.properties) {
|
|
4704
|
-
if (propNode.kind === SyntaxKind.ProjectionModelProperty) {
|
|
4705
|
-
const prop = evalProjectionModelProperty(propNode, modelType);
|
|
4706
|
-
if (prop.kind === "Return") {
|
|
4707
|
-
return prop;
|
|
4708
|
-
}
|
|
4709
|
-
modelType.properties.set(prop.name, prop);
|
|
4710
|
-
}
|
|
4711
|
-
else {
|
|
4712
|
-
const props = evalProjectionModelSpreadProperty(propNode);
|
|
4713
|
-
if (!Array.isArray(props)) {
|
|
4714
|
-
// return record
|
|
4715
|
-
return props;
|
|
4716
|
-
}
|
|
4717
|
-
for (const newProp of props) {
|
|
4718
|
-
modelType.properties.set(newProp.name, newProp);
|
|
4719
|
-
}
|
|
4720
|
-
}
|
|
4721
|
-
}
|
|
4722
|
-
return modelType;
|
|
4723
|
-
}
|
|
4724
|
-
function evalProjectionModelProperty(node, model) {
|
|
4725
|
-
const type = evalProjectionNode(node.value);
|
|
4726
|
-
if (type.kind === "Return") {
|
|
4727
|
-
return type;
|
|
4728
|
-
}
|
|
4729
|
-
return createType({
|
|
4730
|
-
kind: "ModelProperty",
|
|
4731
|
-
name: node.id.sv,
|
|
4732
|
-
node: node,
|
|
4733
|
-
decorators: [],
|
|
4734
|
-
optional: node.optional,
|
|
4735
|
-
type,
|
|
4736
|
-
model,
|
|
4737
|
-
});
|
|
4738
|
-
}
|
|
4739
|
-
function evalProjectionModelSpreadProperty(node) {
|
|
4740
|
-
const target = evalProjectionNode(node.target);
|
|
4741
|
-
if (target.kind === "Return") {
|
|
4742
|
-
return target;
|
|
4743
|
-
}
|
|
4744
|
-
if (target.kind !== "Model") {
|
|
4745
|
-
throw new ProjectionError(`Can only spread models`);
|
|
4746
|
-
}
|
|
4747
|
-
const props = [];
|
|
4748
|
-
// copy each property
|
|
4749
|
-
for (const prop of walkPropertiesInherited(target)) {
|
|
4750
|
-
const newProp = cloneType(prop, { sourceProperty: prop });
|
|
4751
|
-
props.push(newProp);
|
|
4752
|
-
}
|
|
4753
|
-
return props;
|
|
4754
|
-
}
|
|
4755
|
-
function evalProjectionRelationalExpression(node) {
|
|
4756
|
-
const left = evalProjectionNode(node.left);
|
|
4757
|
-
if (left.kind === "Return") {
|
|
4758
|
-
return left;
|
|
4759
|
-
}
|
|
4760
|
-
else if (left.kind !== "Number" && left.kind !== "String") {
|
|
4761
|
-
throw new ProjectionError("Can only compare numbers or strings");
|
|
4762
|
-
}
|
|
4763
|
-
const right = evalProjectionNode(node.right);
|
|
4764
|
-
if (right.kind === "Return") {
|
|
4765
|
-
return right;
|
|
4766
|
-
}
|
|
4767
|
-
else if (right.kind !== "Number" && right.kind !== "String") {
|
|
4768
|
-
throw new ProjectionError("Can only compare numbers or strings");
|
|
4769
|
-
}
|
|
4770
|
-
if (left.kind !== right.kind) {
|
|
4771
|
-
throw new ProjectionError("Can't compare numbers and strings");
|
|
4772
|
-
}
|
|
4773
|
-
switch (node.op) {
|
|
4774
|
-
case "<":
|
|
4775
|
-
return createLiteralType(left.value < right.value);
|
|
4776
|
-
case "<=":
|
|
4777
|
-
return createLiteralType(left.value <= right.value);
|
|
4778
|
-
case ">":
|
|
4779
|
-
return createLiteralType(left.value > right.value);
|
|
4780
|
-
case ">=":
|
|
4781
|
-
return createLiteralType(left.value >= right.value);
|
|
4782
|
-
}
|
|
4783
|
-
}
|
|
4784
|
-
function evalProjectionUnaryExpression(node) {
|
|
4785
|
-
const target = evalProjectionNode(node.target);
|
|
4786
|
-
if (target.kind !== "Boolean") {
|
|
4787
|
-
throw new ProjectionError("Can't negate a non-boolean");
|
|
4788
|
-
}
|
|
4789
|
-
switch (node.op) {
|
|
4790
|
-
case "!":
|
|
4791
|
-
return createLiteralType(!target.value);
|
|
4792
|
-
}
|
|
4793
|
-
}
|
|
4794
|
-
function evalProjectionEqualityExpression(node) {
|
|
4795
|
-
const left = evalProjectionNode(node.left);
|
|
4796
|
-
if (left.kind === "Return") {
|
|
4797
|
-
return left;
|
|
4798
|
-
}
|
|
4799
|
-
else if (left.kind !== "Number" && left.kind !== "String") {
|
|
4800
|
-
throw new ProjectionError("Comparisons must be strings or numbers");
|
|
4801
|
-
}
|
|
4802
|
-
const right = evalProjectionNode(node.right);
|
|
4803
|
-
if (right.kind === "Return") {
|
|
4804
|
-
return right;
|
|
4805
|
-
}
|
|
4806
|
-
else if (right.kind !== "Number" && right.kind !== "String") {
|
|
4807
|
-
throw new ProjectionError("Comparisons must be strings or numbers");
|
|
4808
|
-
}
|
|
4809
|
-
if (right.kind !== left.kind) {
|
|
4810
|
-
throw new ProjectionError("Can't compare number and string");
|
|
4811
|
-
}
|
|
4812
|
-
switch (node.op) {
|
|
4813
|
-
case "==":
|
|
4814
|
-
return createLiteralType(left.value === right.value);
|
|
4815
|
-
case "!=":
|
|
4816
|
-
return createLiteralType(left.value !== right.value);
|
|
4817
|
-
}
|
|
4818
|
-
}
|
|
4819
|
-
function evalProjectionIfExpression(node) {
|
|
4820
|
-
let ifExpr = node;
|
|
4821
|
-
while (ifExpr) {
|
|
4822
|
-
const test = evalProjectionNode(ifExpr.test);
|
|
4823
|
-
if (test.kind === "Return") {
|
|
4824
|
-
return test;
|
|
4825
|
-
}
|
|
4826
|
-
if (typeIsTruthy(test)) {
|
|
4827
|
-
return evalProjectionBlockExpression(ifExpr.consequent);
|
|
4828
|
-
}
|
|
4829
|
-
else if (ifExpr.alternate &&
|
|
4830
|
-
ifExpr.alternate.kind === SyntaxKind.ProjectionBlockExpression) {
|
|
4831
|
-
return evalProjectionBlockExpression(ifExpr.alternate);
|
|
4832
|
-
}
|
|
4833
|
-
else {
|
|
4834
|
-
ifExpr = ifExpr.alternate;
|
|
4835
|
-
}
|
|
4836
|
-
}
|
|
4837
|
-
return voidType;
|
|
4838
|
-
}
|
|
4839
|
-
function typeIsTruthy(t) {
|
|
4840
|
-
switch (t.kind) {
|
|
4841
|
-
case "Boolean":
|
|
4842
|
-
return t.value;
|
|
4843
|
-
case "Number":
|
|
4844
|
-
return !!t.value;
|
|
4845
|
-
case "String":
|
|
4846
|
-
return !!t.value;
|
|
4847
|
-
default:
|
|
4848
|
-
return true;
|
|
4849
|
-
}
|
|
4850
|
-
}
|
|
4851
|
-
function createEvalContext(node, parent) {
|
|
4852
|
-
return {
|
|
4853
|
-
node,
|
|
4854
|
-
locals: new Map(),
|
|
4855
|
-
parent,
|
|
4856
|
-
};
|
|
4857
|
-
}
|
|
4858
|
-
function evalProjectionBlockExpression(node) {
|
|
4859
|
-
let lastVal = voidType;
|
|
4860
|
-
for (const stmt of node.statements) {
|
|
4861
|
-
const stmtValue = evalProjectionNode(stmt);
|
|
4862
|
-
if (stmtValue.kind === "Return") {
|
|
4863
|
-
return stmtValue;
|
|
4864
|
-
}
|
|
4865
|
-
lastVal = stmtValue;
|
|
4866
|
-
}
|
|
4867
|
-
return lastVal;
|
|
4868
|
-
}
|
|
4869
|
-
function evalProjectionArithmeticExpression(node) {
|
|
4870
|
-
const lhs = evalProjectionNode(node.left);
|
|
4871
|
-
if (lhs.kind === "Return") {
|
|
4872
|
-
return lhs;
|
|
4873
|
-
}
|
|
4874
|
-
if (lhs.kind !== "Number" && lhs.kind !== "String") {
|
|
4875
|
-
throw new ProjectionError(`Operator ${node.op} can only apply to strings or numbers`);
|
|
4876
|
-
}
|
|
4877
|
-
const rhs = evalProjectionNode(node.right);
|
|
4878
|
-
if (rhs.kind === "Return") {
|
|
4879
|
-
return rhs;
|
|
4880
|
-
}
|
|
4881
|
-
if (rhs.kind !== "Number" && rhs.kind !== "String") {
|
|
4882
|
-
throw new ProjectionError(`Operator ${node.op} can only apply to strings or numbers`);
|
|
4883
|
-
}
|
|
4884
|
-
if (rhs.kind !== lhs.kind) {
|
|
4885
|
-
throw new ProjectionError(`Operator ${node.op}'s operands need to be the same type`);
|
|
4886
|
-
}
|
|
4887
|
-
if (lhs.kind === "String") {
|
|
4888
|
-
return createLiteralType(lhs.value + rhs.value);
|
|
4889
|
-
}
|
|
4890
|
-
else {
|
|
4891
|
-
return createLiteralType(lhs.value + rhs.value);
|
|
4892
|
-
}
|
|
4893
|
-
}
|
|
4894
|
-
function evalProjection(node, target, args) {
|
|
4895
|
-
if (node.direction === "<error>") {
|
|
4896
|
-
throw new ProjectionError("Cannot evaluate projection with invalid direction.");
|
|
4897
|
-
}
|
|
4898
|
-
let topLevelProjection = false;
|
|
4899
|
-
if (!currentProjectionDirection) {
|
|
4900
|
-
topLevelProjection = true;
|
|
4901
|
-
currentProjectionDirection = node.direction;
|
|
4902
|
-
}
|
|
4903
|
-
if (currentProjectionDirection === "from" && !target.projectionSource) {
|
|
4904
|
-
// this model wasn't projected, so we'll just return the target
|
|
4905
|
-
return target;
|
|
4906
|
-
}
|
|
4907
|
-
const originalContext = evalContext;
|
|
4908
|
-
evalContext = createEvalContext(node);
|
|
4909
|
-
for (const [i, param] of node.parameters.entries()) {
|
|
4910
|
-
if (!args[i]) {
|
|
4911
|
-
throw new ProjectionError("need argument for parameter " + SyntaxKind[node.parameters[i].kind]);
|
|
4912
|
-
}
|
|
4913
|
-
const argVal = args[i];
|
|
4914
|
-
let typeVal;
|
|
4915
|
-
if (typeof argVal === "number" || typeof argVal === "string" || typeof argVal === "boolean") {
|
|
4916
|
-
typeVal = createLiteralType(argVal);
|
|
4917
|
-
}
|
|
4918
|
-
else {
|
|
4919
|
-
typeVal = argVal;
|
|
4920
|
-
}
|
|
4921
|
-
evalContext.locals.set(param.id.sv, typeVal);
|
|
4922
|
-
}
|
|
4923
|
-
evalContext.locals.set("self", target);
|
|
4924
|
-
let lastVal = voidType;
|
|
4925
|
-
for (const item of node.body) {
|
|
4926
|
-
lastVal = evalProjectionNode(item);
|
|
4927
|
-
if (lastVal.kind === "Return") {
|
|
4928
|
-
break;
|
|
4929
|
-
}
|
|
4930
|
-
}
|
|
4931
|
-
if (topLevelProjection) {
|
|
4932
|
-
currentProjectionDirection = undefined;
|
|
4933
|
-
}
|
|
4934
|
-
const selfResult = evalContext.locals.get("self");
|
|
4935
|
-
evalContext = originalContext;
|
|
4936
|
-
if (lastVal.kind === "Return") {
|
|
4937
|
-
return lastVal.value;
|
|
4938
|
-
}
|
|
4939
|
-
else {
|
|
4940
|
-
return selfResult;
|
|
4941
|
-
}
|
|
4942
|
-
}
|
|
4943
|
-
function evalProjectionExpressionStatement(node) {
|
|
4944
|
-
return evalProjectionNode(node.expr);
|
|
4945
|
-
}
|
|
4946
|
-
function evalProjectionCallExpression(node) {
|
|
4947
|
-
const target = evalProjectionNode(node.target);
|
|
4948
|
-
if (!target)
|
|
4949
|
-
throw new ProjectionError("target undefined");
|
|
4950
|
-
const args = [];
|
|
4951
|
-
for (const arg of node.arguments) {
|
|
4952
|
-
args.push(evalProjectionNode(arg));
|
|
4953
|
-
}
|
|
4954
|
-
if (target.kind !== "Function") {
|
|
4955
|
-
throw new ProjectionError("Can't call non-function, got type " + target.kind);
|
|
4956
|
-
}
|
|
4957
|
-
return target.implementation(...args);
|
|
4958
|
-
}
|
|
4959
|
-
function evalProjectionMemberExpression(node) {
|
|
4960
|
-
const base = evalProjectionNode(node.base);
|
|
4961
|
-
if (base.kind === "Return") {
|
|
4962
|
-
return base;
|
|
4963
|
-
}
|
|
4964
|
-
const member = node.id.sv;
|
|
4965
|
-
const selector = node.selector;
|
|
4966
|
-
if (selector === ".") {
|
|
4967
|
-
switch (base.kind) {
|
|
4968
|
-
case "Namespace":
|
|
4969
|
-
const sym = base.node.symbol.exports.get(member);
|
|
4970
|
-
if (sym) {
|
|
4971
|
-
const links = getSymbolLinks(sym);
|
|
4972
|
-
return links.declaredType || links.type || errorType;
|
|
4973
|
-
}
|
|
4974
|
-
else {
|
|
4975
|
-
throw new ProjectionError(`Namespace doesn't have member ${member}`);
|
|
4976
|
-
}
|
|
4977
|
-
case "Model":
|
|
4978
|
-
const prop = base.properties.get(member);
|
|
4979
|
-
if (!prop) {
|
|
4980
|
-
throw new ProjectionError(`Model doesn't have property ${member}`);
|
|
4981
|
-
}
|
|
4982
|
-
return prop;
|
|
4983
|
-
case "Enum":
|
|
4984
|
-
const enumMember = base.members.get(member);
|
|
4985
|
-
if (!enumMember) {
|
|
4986
|
-
throw new ProjectionError(`Enum doesn't have member ${member}`);
|
|
4987
|
-
}
|
|
4988
|
-
return enumMember;
|
|
4989
|
-
case "Union":
|
|
4990
|
-
const variant = base.variants.get(member);
|
|
4991
|
-
if (!variant) {
|
|
4992
|
-
throw new ProjectionError(`Union doesn't have variant ${member}`);
|
|
4993
|
-
}
|
|
4994
|
-
return variant;
|
|
4995
|
-
default:
|
|
4996
|
-
throw new ProjectionError(`Can't get member "${member}" of type ${base.kind} because it has no members. Did you mean to use "::" instead of "."?`);
|
|
4997
|
-
}
|
|
4998
|
-
}
|
|
4999
|
-
switch (base.kind) {
|
|
5000
|
-
case "Object":
|
|
5001
|
-
return base.properties[member] || errorType;
|
|
5002
|
-
default:
|
|
5003
|
-
const typeOps = projectionMembers[base.kind];
|
|
5004
|
-
if (!typeOps) {
|
|
5005
|
-
throw new ProjectionError(`${base.kind} doesn't have an object model member named ${member}`);
|
|
5006
|
-
}
|
|
5007
|
-
// any cast needed to ensure we don't get a too complex union error on the call
|
|
5008
|
-
// to op further down.
|
|
5009
|
-
const op = typeOps[member];
|
|
5010
|
-
if (!op) {
|
|
5011
|
-
throw new ProjectionError(`${base.kind} doesn't have an object model member named ${member}`);
|
|
5012
|
-
}
|
|
5013
|
-
return op(base);
|
|
5014
|
-
}
|
|
5015
|
-
}
|
|
5016
|
-
function createFunctionType(fn) {
|
|
5017
|
-
const parameters = [];
|
|
5018
|
-
return createType({
|
|
5019
|
-
kind: "Function",
|
|
5020
|
-
name: "",
|
|
5021
|
-
parameters,
|
|
5022
|
-
returnType: unknownType,
|
|
5023
|
-
implementation: fn,
|
|
5024
|
-
});
|
|
5025
|
-
}
|
|
5026
4416
|
function createLiteralType(value, node) {
|
|
5027
4417
|
if (program.literalTypes.has(value)) {
|
|
5028
4418
|
return program.literalTypes.get(value);
|
|
@@ -5055,101 +4445,6 @@ export function createChecker(program, resolver) {
|
|
|
5055
4445
|
program.literalTypes.set(value, type);
|
|
5056
4446
|
return type;
|
|
5057
4447
|
}
|
|
5058
|
-
function evalProjectionDecoratorReference(node) {
|
|
5059
|
-
const ref = resolveTypeReferenceSym(node.target, undefined, true);
|
|
5060
|
-
if (!ref)
|
|
5061
|
-
throw new ProjectionError("Can't find decorator.");
|
|
5062
|
-
compilerAssert(ref.flags & 1024 /* SymbolFlags.Decorator */, "should only resolve decorator symbols");
|
|
5063
|
-
return createFunctionType((...args) => {
|
|
5064
|
-
ref.value({ program }, ...args.map(unsafe_projectionArgumentMarshalForJS));
|
|
5065
|
-
return voidType;
|
|
5066
|
-
});
|
|
5067
|
-
}
|
|
5068
|
-
function evalProjectionIdentifier(node) {
|
|
5069
|
-
// first check the eval context
|
|
5070
|
-
let currentContext = evalContext;
|
|
5071
|
-
while (currentContext) {
|
|
5072
|
-
if (currentContext.locals.has(node.sv)) {
|
|
5073
|
-
return currentContext.locals.get(node.sv);
|
|
5074
|
-
}
|
|
5075
|
-
currentContext = currentContext.parent;
|
|
5076
|
-
}
|
|
5077
|
-
// next, resolve outside
|
|
5078
|
-
const { finalSymbol: ref } = resolver.resolveTypeReference(node);
|
|
5079
|
-
if (!ref)
|
|
5080
|
-
throw new ProjectionError("Unknown identifier " + node.sv);
|
|
5081
|
-
if (ref.flags & 1024 /* SymbolFlags.Decorator */) {
|
|
5082
|
-
// shouldn't ever resolve a decorator symbol here (without passing
|
|
5083
|
-
// true to resolveTypeReference)
|
|
5084
|
-
return errorType;
|
|
5085
|
-
}
|
|
5086
|
-
else if (ref.flags & 8192 /* SymbolFlags.Function */) {
|
|
5087
|
-
// TODO: store this in a symbol link probably?
|
|
5088
|
-
const t = createFunctionType((...args) => {
|
|
5089
|
-
const retval = ref.value(program, ...args.map(unsafe_projectionArgumentMarshalForJS));
|
|
5090
|
-
return marshalProjectionReturn(retval, { functionName: node.sv });
|
|
5091
|
-
});
|
|
5092
|
-
return t;
|
|
5093
|
-
}
|
|
5094
|
-
else {
|
|
5095
|
-
const links = getSymbolLinks(ref);
|
|
5096
|
-
compilerAssert(links.declaredType, "Should have checked all types by now");
|
|
5097
|
-
return links.declaredType;
|
|
5098
|
-
}
|
|
5099
|
-
}
|
|
5100
|
-
function marshalProjectionReturn(value, options = {}) {
|
|
5101
|
-
if (typeof value === "boolean" || typeof value === "string" || typeof value === "number") {
|
|
5102
|
-
return createLiteralType(value);
|
|
5103
|
-
}
|
|
5104
|
-
if (typeof value === "object" && value !== null) {
|
|
5105
|
-
if ("kind" in value) {
|
|
5106
|
-
return value;
|
|
5107
|
-
}
|
|
5108
|
-
else {
|
|
5109
|
-
// this could probably be more robust
|
|
5110
|
-
return createType({
|
|
5111
|
-
kind: "Object",
|
|
5112
|
-
properties: value,
|
|
5113
|
-
});
|
|
5114
|
-
}
|
|
5115
|
-
}
|
|
5116
|
-
if (options.functionName) {
|
|
5117
|
-
throw new ProjectionError(`Can't marshal value "${value}" returned from JS function "${options.functionName}" into typespec`);
|
|
5118
|
-
}
|
|
5119
|
-
else {
|
|
5120
|
-
throw new ProjectionError(`Can't marshal value "${value}" into typespec`);
|
|
5121
|
-
}
|
|
5122
|
-
}
|
|
5123
|
-
function evalProjectionLambdaExpression(node) {
|
|
5124
|
-
return createFunctionType((...args) => {
|
|
5125
|
-
return callLambdaExpression(node, args);
|
|
5126
|
-
});
|
|
5127
|
-
}
|
|
5128
|
-
function callLambdaExpression(node, args) {
|
|
5129
|
-
const originalContext = evalContext;
|
|
5130
|
-
evalContext = createEvalContext(node, originalContext);
|
|
5131
|
-
for (const [i, param] of node.parameters.entries()) {
|
|
5132
|
-
evalContext.locals.set(param.id.sv, args[i]);
|
|
5133
|
-
}
|
|
5134
|
-
const retval = evalProjectionBlockExpression(node.body);
|
|
5135
|
-
evalContext = originalContext;
|
|
5136
|
-
if (retval.kind === "Return") {
|
|
5137
|
-
return retval.value;
|
|
5138
|
-
}
|
|
5139
|
-
return retval;
|
|
5140
|
-
}
|
|
5141
|
-
function evalStringLiteral(node) {
|
|
5142
|
-
return createLiteralType(node.value, node);
|
|
5143
|
-
}
|
|
5144
|
-
function evalNumericLiteral(node) {
|
|
5145
|
-
return createLiteralType(node.value, node);
|
|
5146
|
-
}
|
|
5147
|
-
function evalBooleanLiteral(node) {
|
|
5148
|
-
return createLiteralType(node.value, node);
|
|
5149
|
-
}
|
|
5150
|
-
function project(target, projection, args = []) {
|
|
5151
|
-
return evalProjection(projection, target, args.map((x) => marshalProjectionReturn(x)));
|
|
5152
|
-
}
|
|
5153
4448
|
/**
|
|
5154
4449
|
* Check if the source type can be assigned to the target type and emit diagnostics
|
|
5155
4450
|
* @param source Type of a value
|
|
@@ -5196,7 +4491,6 @@ export function createChecker(program, resolver) {
|
|
|
5196
4491
|
return related;
|
|
5197
4492
|
}
|
|
5198
4493
|
function isStdType(type, stdType) {
|
|
5199
|
-
type = type.projectionBase ?? type;
|
|
5200
4494
|
if ((type.kind !== "Model" && type.kind !== "Scalar") ||
|
|
5201
4495
|
type.namespace === undefined ||
|
|
5202
4496
|
!isTypeSpecNamespace(type.namespace))
|
|
@@ -5624,21 +4918,6 @@ const defaultSymbolResolutionOptions = {
|
|
|
5624
4918
|
resolveDecorators: false,
|
|
5625
4919
|
checkTemplateTypes: true,
|
|
5626
4920
|
};
|
|
5627
|
-
/**
|
|
5628
|
-
* Convert LEGACY for projection.
|
|
5629
|
-
* THIS IS BROKEN. Some decorators will not receive the correct type.
|
|
5630
|
-
* It has been broken since the introduction of valueof.
|
|
5631
|
-
* As projection as put on hold as long as versioning works we are in a good state.
|
|
5632
|
-
*/
|
|
5633
|
-
function unsafe_projectionArgumentMarshalForJS(arg) {
|
|
5634
|
-
if (arg.kind === "Boolean" || arg.kind === "String" || arg.kind === "Number") {
|
|
5635
|
-
return arg.value;
|
|
5636
|
-
}
|
|
5637
|
-
else if (arg.kind === "StringTemplate") {
|
|
5638
|
-
return arg.stringValue;
|
|
5639
|
-
}
|
|
5640
|
-
return arg;
|
|
5641
|
-
}
|
|
5642
4921
|
function printTypeReferenceNode(node) {
|
|
5643
4922
|
switch (node.kind) {
|
|
5644
4923
|
case SyntaxKind.MemberExpression:
|