@tsonic/frontend 0.0.62 → 0.0.63
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/.tsbuildinfo +1 -1
- package/dist/dependency-graph.d.ts +1 -1
- package/dist/dependency-graph.d.ts.map +1 -1
- package/dist/dependency-graph.js +1 -1
- package/dist/dependency-graph.js.map +1 -1
- package/dist/dotnet-metadata.d.ts +0 -12
- package/dist/dotnet-metadata.d.ts.map +1 -1
- package/dist/dotnet-metadata.js +0 -24
- package/dist/dotnet-metadata.js.map +1 -1
- package/dist/generic-function-values.d.ts +11 -0
- package/dist/generic-function-values.d.ts.map +1 -0
- package/dist/generic-function-values.js +243 -0
- package/dist/generic-function-values.js.map +1 -0
- package/dist/generic-function-values.test.d.ts +2 -0
- package/dist/generic-function-values.test.d.ts.map +1 -0
- package/dist/generic-function-values.test.js +256 -0
- package/dist/generic-function-values.test.js.map +1 -0
- package/dist/graph/extraction/imports.d.ts +5 -0
- package/dist/graph/extraction/imports.d.ts.map +1 -1
- package/dist/graph/extraction/imports.js +30 -0
- package/dist/graph/extraction/imports.js.map +1 -1
- package/dist/graph/extraction/index.d.ts +1 -1
- package/dist/graph/extraction/index.d.ts.map +1 -1
- package/dist/graph/extraction/index.js +1 -1
- package/dist/graph/extraction/index.js.map +1 -1
- package/dist/graph/extraction/orchestrator.d.ts.map +1 -1
- package/dist/graph/extraction/orchestrator.js +16 -2
- package/dist/graph/extraction/orchestrator.js.map +1 -1
- package/dist/graph/extraction.d.ts +1 -1
- package/dist/graph/extraction.d.ts.map +1 -1
- package/dist/graph/extraction.js +1 -1
- package/dist/graph/extraction.js.map +1 -1
- package/dist/ir/binding/binding-factory.d.ts +17 -0
- package/dist/ir/binding/binding-factory.d.ts.map +1 -0
- package/dist/ir/binding/binding-factory.js +765 -0
- package/dist/ir/binding/binding-factory.js.map +1 -0
- package/dist/ir/binding/binding-helpers.d.ts +90 -0
- package/dist/ir/binding/binding-helpers.d.ts.map +1 -0
- package/dist/ir/binding/binding-helpers.js +387 -0
- package/dist/ir/binding/binding-helpers.js.map +1 -0
- package/dist/ir/binding/binding-types.d.ts +203 -0
- package/dist/ir/binding/binding-types.d.ts.map +1 -0
- package/dist/ir/binding/binding-types.js +9 -0
- package/dist/ir/binding/binding-types.js.map +1 -0
- package/dist/ir/binding/index.d.ts +4 -158
- package/dist/ir/binding/index.d.ts.map +1 -1
- package/dist/ir/binding/index.js +3 -1134
- package/dist/ir/binding/index.js.map +1 -1
- package/dist/ir/builder.test.js +223 -0
- package/dist/ir/builder.test.js.map +1 -1
- package/dist/ir/converters/anonymous-synthesis.d.ts +3 -3
- package/dist/ir/converters/anonymous-synthesis.d.ts.map +1 -1
- package/dist/ir/converters/anonymous-synthesis.js +45 -8
- package/dist/ir/converters/anonymous-synthesis.js.map +1 -1
- package/dist/ir/converters/expressions/access/access-converter.d.ts +14 -0
- package/dist/ir/converters/expressions/access/access-converter.d.ts.map +1 -0
- package/dist/ir/converters/expressions/access/access-converter.js +141 -0
- package/dist/ir/converters/expressions/access/access-converter.js.map +1 -0
- package/dist/ir/converters/expressions/access/binding-resolution.d.ts +35 -0
- package/dist/ir/converters/expressions/access/binding-resolution.d.ts.map +1 -0
- package/dist/ir/converters/expressions/access/binding-resolution.js +384 -0
- package/dist/ir/converters/expressions/access/binding-resolution.js.map +1 -0
- package/dist/ir/converters/expressions/access/member-resolution.d.ts +67 -0
- package/dist/ir/converters/expressions/access/member-resolution.d.ts.map +1 -0
- package/dist/ir/converters/expressions/access/member-resolution.js +262 -0
- package/dist/ir/converters/expressions/access/member-resolution.js.map +1 -0
- package/dist/ir/converters/expressions/access.d.ts +1 -7
- package/dist/ir/converters/expressions/access.d.ts.map +1 -1
- package/dist/ir/converters/expressions/access.js +1 -720
- package/dist/ir/converters/expressions/access.js.map +1 -1
- package/dist/ir/converters/expressions/calls/call-converter.d.ts +23 -0
- package/dist/ir/converters/expressions/calls/call-converter.d.ts.map +1 -0
- package/dist/ir/converters/expressions/calls/call-converter.js +526 -0
- package/dist/ir/converters/expressions/calls/call-converter.js.map +1 -0
- package/dist/ir/converters/expressions/calls/call-site-analysis.d.ts +53 -0
- package/dist/ir/converters/expressions/calls/call-site-analysis.d.ts.map +1 -0
- package/dist/ir/converters/expressions/calls/call-site-analysis.js +554 -0
- package/dist/ir/converters/expressions/calls/call-site-analysis.js.map +1 -0
- package/dist/ir/converters/expressions/calls/new-converter.d.ts +21 -0
- package/dist/ir/converters/expressions/calls/new-converter.d.ts.map +1 -0
- package/dist/ir/converters/expressions/calls/new-converter.js +182 -0
- package/dist/ir/converters/expressions/calls/new-converter.js.map +1 -0
- package/dist/ir/converters/expressions/calls.d.ts +2 -28
- package/dist/ir/converters/expressions/calls.d.ts.map +1 -1
- package/dist/ir/converters/expressions/calls.js +2 -1344
- package/dist/ir/converters/expressions/calls.js.map +1 -1
- package/dist/ir/converters/expressions/collections.d.ts.map +1 -1
- package/dist/ir/converters/expressions/collections.js +37 -6
- package/dist/ir/converters/expressions/collections.js.map +1 -1
- package/dist/ir/converters/expressions/functions.js +1 -1
- package/dist/ir/converters/expressions/functions.js.map +1 -1
- package/dist/ir/converters/expressions/helpers.d.ts.map +1 -1
- package/dist/ir/converters/expressions/helpers.js +1 -0
- package/dist/ir/converters/expressions/helpers.js.map +1 -1
- package/dist/ir/converters/expressions/other.d.ts.map +1 -1
- package/dist/ir/converters/expressions/other.js +3 -2
- package/dist/ir/converters/expressions/other.js.map +1 -1
- package/dist/ir/converters/flow-narrowing.d.ts.map +1 -1
- package/dist/ir/converters/flow-narrowing.js +3 -2
- package/dist/ir/converters/flow-narrowing.js.map +1 -1
- package/dist/ir/converters/statements/declarations/classes/methods.js +1 -1
- package/dist/ir/converters/statements/declarations/classes/methods.js.map +1 -1
- package/dist/ir/converters/statements/declarations/type-aliases.js +1 -1
- package/dist/ir/converters/statements/declarations/type-aliases.js.map +1 -1
- package/dist/ir/converters/statements/declarations/variables.d.ts +2 -2
- package/dist/ir/converters/statements/declarations/variables.d.ts.map +1 -1
- package/dist/ir/converters/statements/declarations/variables.js +289 -2
- package/dist/ir/converters/statements/declarations/variables.js.map +1 -1
- package/dist/ir/expression-converter.d.ts +0 -1
- package/dist/ir/expression-converter.d.ts.map +1 -1
- package/dist/ir/expression-converter.js +0 -2
- package/dist/ir/expression-converter.js.map +1 -1
- package/dist/ir/generic-function-value-lowering.test.d.ts +2 -0
- package/dist/ir/generic-function-value-lowering.test.d.ts.map +1 -0
- package/dist/ir/generic-function-value-lowering.test.js +312 -0
- package/dist/ir/generic-function-value-lowering.test.js.map +1 -0
- package/dist/ir/generic-validator.d.ts +3 -4
- package/dist/ir/generic-validator.d.ts.map +1 -1
- package/dist/ir/generic-validator.js +3 -35
- package/dist/ir/generic-validator.js.map +1 -1
- package/dist/ir/program-context.d.ts +7 -0
- package/dist/ir/program-context.d.ts.map +1 -1
- package/dist/ir/program-context.js +1 -0
- package/dist/ir/program-context.js.map +1 -1
- package/dist/ir/statement-converter.d.ts +0 -2
- package/dist/ir/statement-converter.d.ts.map +1 -1
- package/dist/ir/statement-converter.js +0 -3
- package/dist/ir/statement-converter.js.map +1 -1
- package/dist/ir/type-system/internal/handle-types.d.ts +16 -16
- package/dist/ir/type-system/internal/handle-types.d.ts.map +1 -1
- package/dist/ir/type-system/internal/nominal-env.d.ts +0 -2
- package/dist/ir/type-system/internal/nominal-env.d.ts.map +1 -1
- package/dist/ir/type-system/internal/nominal-env.js +2 -6
- package/dist/ir/type-system/internal/nominal-env.js.map +1 -1
- package/dist/ir/type-system/internal/type-converter/converter.d.ts +3 -1
- package/dist/ir/type-system/internal/type-converter/converter.d.ts.map +1 -1
- package/dist/ir/type-system/internal/type-converter/converter.js +3 -1
- package/dist/ir/type-system/internal/type-converter/converter.js.map +1 -1
- package/dist/ir/type-system/internal/type-converter/objects.js +7 -1
- package/dist/ir/type-system/internal/type-converter/objects.js.map +1 -1
- package/dist/ir/type-system/internal/type-converter/orchestrator.d.ts +0 -2
- package/dist/ir/type-system/internal/type-converter/orchestrator.d.ts.map +1 -1
- package/dist/ir/type-system/internal/type-converter/orchestrator.js +315 -23
- package/dist/ir/type-system/internal/type-converter/orchestrator.js.map +1 -1
- package/dist/ir/type-system/internal/type-converter/orchestrator.test.d.ts +2 -0
- package/dist/ir/type-system/internal/type-converter/orchestrator.test.d.ts.map +1 -0
- package/dist/ir/type-system/internal/type-converter/orchestrator.test.js +265 -0
- package/dist/ir/type-system/internal/type-converter/orchestrator.test.js.map +1 -0
- package/dist/ir/type-system/internal/type-converter/primitives.d.ts.map +1 -1
- package/dist/ir/type-system/internal/type-converter/primitives.js +5 -0
- package/dist/ir/type-system/internal/type-converter/primitives.js.map +1 -1
- package/dist/ir/type-system/internal/type-converter/references.d.ts.map +1 -1
- package/dist/ir/type-system/internal/type-converter/references.js +67 -29
- package/dist/ir/type-system/internal/type-converter/references.js.map +1 -1
- package/dist/ir/type-system/internal/type-converter/utility-types.d.ts.map +1 -1
- package/dist/ir/type-system/internal/type-converter/utility-types.js +145 -0
- package/dist/ir/type-system/internal/type-converter/utility-types.js.map +1 -1
- package/dist/ir/type-system/internal/type-converter/utility-types.test.js +91 -1
- package/dist/ir/type-system/internal/type-converter/utility-types.test.js.map +1 -1
- package/dist/ir/type-system/internal/type-registry.d.ts +1 -1
- package/dist/ir/type-system/internal/type-registry.js +7 -7
- package/dist/ir/type-system/internal/type-registry.js.map +1 -1
- package/dist/ir/type-system/internal/universe/alias-table.d.ts +0 -14
- package/dist/ir/type-system/internal/universe/alias-table.d.ts.map +1 -1
- package/dist/ir/type-system/internal/universe/alias-table.js +0 -17
- package/dist/ir/type-system/internal/universe/alias-table.js.map +1 -1
- package/dist/ir/type-system/internal/universe/clr-catalog.d.ts +3 -0
- package/dist/ir/type-system/internal/universe/clr-catalog.d.ts.map +1 -1
- package/dist/ir/type-system/internal/universe/clr-catalog.js +4 -1044
- package/dist/ir/type-system/internal/universe/clr-catalog.js.map +1 -1
- package/dist/ir/type-system/internal/universe/clr-entry-converter.d.ts +51 -0
- package/dist/ir/type-system/internal/universe/clr-entry-converter.d.ts.map +1 -0
- package/dist/ir/type-system/internal/universe/clr-entry-converter.js +657 -0
- package/dist/ir/type-system/internal/universe/clr-entry-converter.js.map +1 -0
- package/dist/ir/type-system/internal/universe/clr-type-parser.d.ts +52 -0
- package/dist/ir/type-system/internal/universe/clr-type-parser.d.ts.map +1 -0
- package/dist/ir/type-system/internal/universe/clr-type-parser.js +415 -0
- package/dist/ir/type-system/internal/universe/clr-type-parser.js.map +1 -0
- package/dist/ir/type-system/internal/universe/index.d.ts +1 -1
- package/dist/ir/type-system/internal/universe/index.d.ts.map +1 -1
- package/dist/ir/type-system/internal/universe/index.js +1 -3
- package/dist/ir/type-system/internal/universe/index.js.map +1 -1
- package/dist/ir/type-system/internal/universe/unified-universe.test.js +2 -0
- package/dist/ir/type-system/internal/universe/unified-universe.test.js.map +1 -1
- package/dist/ir/type-system/type-system-call-resolution.d.ts +69 -0
- package/dist/ir/type-system/type-system-call-resolution.d.ts.map +1 -0
- package/dist/ir/type-system/type-system-call-resolution.js +1121 -0
- package/dist/ir/type-system/type-system-call-resolution.js.map +1 -0
- package/dist/ir/type-system/type-system-inference.d.ts +98 -0
- package/dist/ir/type-system/type-system-inference.d.ts.map +1 -0
- package/dist/ir/type-system/type-system-inference.js +1083 -0
- package/dist/ir/type-system/type-system-inference.js.map +1 -0
- package/dist/ir/type-system/type-system-relations.d.ts +15 -0
- package/dist/ir/type-system/type-system-relations.d.ts.map +1 -0
- package/dist/ir/type-system/type-system-relations.js +152 -0
- package/dist/ir/type-system/type-system-relations.js.map +1 -0
- package/dist/ir/type-system/type-system-state.d.ts +436 -0
- package/dist/ir/type-system/type-system-state.d.ts.map +1 -0
- package/dist/ir/type-system/type-system-state.js +212 -0
- package/dist/ir/type-system/type-system-state.js.map +1 -0
- package/dist/ir/type-system/type-system-utilities.d.ts +56 -0
- package/dist/ir/type-system/type-system-utilities.d.ts.map +1 -0
- package/dist/ir/type-system/type-system-utilities.js +373 -0
- package/dist/ir/type-system/type-system-utilities.js.map +1 -0
- package/dist/ir/type-system/type-system.d.ts +17 -358
- package/dist/ir/type-system/type-system.d.ts.map +1 -1
- package/dist/ir/type-system/type-system.js +67 -2945
- package/dist/ir/type-system/type-system.js.map +1 -1
- package/dist/ir/types/index.d.ts +1 -0
- package/dist/ir/types/index.d.ts.map +1 -1
- package/dist/ir/types/index.js +1 -0
- package/dist/ir/types/index.js.map +1 -1
- package/dist/ir/types/ir-substitution.js +1 -1
- package/dist/ir/types/ir-substitution.js.map +1 -1
- package/dist/ir/types/statements.d.ts +1 -1
- package/dist/ir/types/type-ops.d.ts +9 -0
- package/dist/ir/types/type-ops.d.ts.map +1 -0
- package/dist/ir/types/type-ops.js +134 -0
- package/dist/ir/types/type-ops.js.map +1 -0
- package/dist/ir/types/type-ops.test.d.ts +2 -0
- package/dist/ir/types/type-ops.test.d.ts.map +1 -0
- package/dist/ir/types/type-ops.test.js +73 -0
- package/dist/ir/types/type-ops.test.js.map +1 -0
- package/dist/ir/validation/attribute-collection/arg-extractor.d.ts +58 -0
- package/dist/ir/validation/attribute-collection/arg-extractor.d.ts.map +1 -0
- package/dist/ir/validation/attribute-collection/arg-extractor.js +284 -0
- package/dist/ir/validation/attribute-collection/arg-extractor.js.map +1 -0
- package/dist/ir/validation/attribute-collection/marker-parser.d.ts +28 -0
- package/dist/ir/validation/attribute-collection/marker-parser.d.ts.map +1 -0
- package/dist/ir/validation/attribute-collection/marker-parser.js +404 -0
- package/dist/ir/validation/attribute-collection/marker-parser.js.map +1 -0
- package/dist/ir/validation/attribute-collection/orchestrator.d.ts +28 -0
- package/dist/ir/validation/attribute-collection/orchestrator.d.ts.map +1 -0
- package/dist/ir/validation/attribute-collection/orchestrator.js +332 -0
- package/dist/ir/validation/attribute-collection/orchestrator.js.map +1 -0
- package/dist/ir/validation/attribute-collection-pass.d.ts +1 -23
- package/dist/ir/validation/attribute-collection-pass.d.ts.map +1 -1
- package/dist/ir/validation/attribute-collection-pass.js +1 -961
- package/dist/ir/validation/attribute-collection-pass.js.map +1 -1
- package/dist/ir/validation/attribute-collection-pass.test.js +12 -6
- package/dist/ir/validation/attribute-collection-pass.test.js.map +1 -1
- package/dist/ir/validation/soundness-gate.d.ts.map +1 -1
- package/dist/ir/validation/soundness-gate.js +2 -1
- package/dist/ir/validation/soundness-gate.js.map +1 -1
- package/dist/ir/validation/soundness-gate.test.js +69 -0
- package/dist/ir/validation/soundness-gate.test.js.map +1 -1
- package/dist/ir/validation/yield-lowering-pass.d.ts +11 -5
- package/dist/ir/validation/yield-lowering-pass.d.ts.map +1 -1
- package/dist/ir/validation/yield-lowering-pass.js +942 -48
- package/dist/ir/validation/yield-lowering-pass.js.map +1 -1
- package/dist/ir/validation/yield-lowering-pass.test.js +1333 -127
- package/dist/ir/validation/yield-lowering-pass.test.js.map +1 -1
- package/dist/program/binding-loader.d.ts +37 -0
- package/dist/program/binding-loader.d.ts.map +1 -0
- package/dist/program/binding-loader.js +155 -0
- package/dist/program/binding-loader.js.map +1 -0
- package/dist/program/binding-registry.d.ts +106 -0
- package/dist/program/binding-registry.d.ts.map +1 -0
- package/dist/program/binding-registry.js +590 -0
- package/dist/program/binding-registry.js.map +1 -0
- package/dist/program/binding-types.d.ts +166 -0
- package/dist/program/binding-types.d.ts.map +1 -0
- package/dist/program/binding-types.js +57 -0
- package/dist/program/binding-types.js.map +1 -0
- package/dist/program/bindings.d.ts +6 -271
- package/dist/program/bindings.d.ts.map +1 -1
- package/dist/program/bindings.js +7 -781
- package/dist/program/bindings.js.map +1 -1
- package/dist/resolver/clr-bindings-resolver.d.ts +0 -1
- package/dist/resolver/clr-bindings-resolver.d.ts.map +1 -1
- package/dist/resolver/clr-bindings-resolver.js +22 -32
- package/dist/resolver/clr-bindings-resolver.js.map +1 -1
- package/dist/resolver/clr-bindings-resolver.test.js +0 -27
- package/dist/resolver/clr-bindings-resolver.test.js.map +1 -1
- package/dist/resolver/import-resolution.d.ts +1 -1
- package/dist/resolver/import-resolution.d.ts.map +1 -1
- package/dist/resolver/import-resolution.js +2 -7
- package/dist/resolver/import-resolution.js.map +1 -1
- package/dist/resolver/naming.d.ts.map +1 -1
- package/dist/resolver/naming.js +1 -0
- package/dist/resolver/naming.js.map +1 -1
- package/dist/types/diagnostic.d.ts +1 -1
- package/dist/types/diagnostic.d.ts.map +1 -1
- package/dist/types/diagnostic.js.map +1 -1
- package/dist/validation/features.d.ts.map +1 -1
- package/dist/validation/features.js +38 -13
- package/dist/validation/features.js.map +1 -1
- package/dist/validation/features.test.d.ts +2 -0
- package/dist/validation/features.test.d.ts.map +1 -0
- package/dist/validation/features.test.js +273 -0
- package/dist/validation/features.test.js.map +1 -0
- package/dist/validation/generics.d.ts +1 -1
- package/dist/validation/generics.d.ts.map +1 -1
- package/dist/validation/generics.js +2 -26
- package/dist/validation/generics.js.map +1 -1
- package/dist/validation/imports.d.ts.map +1 -1
- package/dist/validation/imports.js +2 -1
- package/dist/validation/imports.js.map +1 -1
- package/dist/validation/imports.test.d.ts +2 -0
- package/dist/validation/imports.test.d.ts.map +1 -0
- package/dist/validation/imports.test.js +112 -0
- package/dist/validation/imports.test.js.map +1 -0
- package/dist/validation/static-safety.d.ts +6 -6
- package/dist/validation/static-safety.d.ts.map +1 -1
- package/dist/validation/static-safety.js +163 -109
- package/dist/validation/static-safety.js.map +1 -1
- package/dist/validation/unsupported-utility-types.d.ts +3 -3
- package/dist/validation/unsupported-utility-types.d.ts.map +1 -1
- package/dist/validation/unsupported-utility-types.js +4 -7
- package/dist/validation/unsupported-utility-types.js.map +1 -1
- package/dist/validator.maximus.test.d.ts +2 -0
- package/dist/validator.maximus.test.d.ts.map +1 -0
- package/dist/validator.maximus.test.js +1214 -0
- package/dist/validator.maximus.test.js.map +1 -0
- package/dist/validator.test.js +152 -18
- package/dist/validator.test.js.map +1 -1
- package/package.json +1 -1
- package/dist/ir/converters/statements/declarations/registry.d.ts +0 -96
- package/dist/ir/converters/statements/declarations/registry.d.ts.map +0 -1
- package/dist/ir/converters/statements/declarations/registry.js +0 -130
- package/dist/ir/converters/statements/declarations/registry.js.map +0 -1
- package/dist/ir/this-parameter-inference.test.d.ts +0 -13
- package/dist/ir/this-parameter-inference.test.d.ts.map +0 -1
- package/dist/ir/this-parameter-inference.test.js +0 -165
- package/dist/ir/this-parameter-inference.test.js.map +0 -1
- package/dist/metadata/bindings-loader.d.ts +0 -41
- package/dist/metadata/bindings-loader.d.ts.map +0 -1
- package/dist/metadata/bindings-loader.js +0 -308
- package/dist/metadata/bindings-loader.js.map +0 -1
- package/dist/metadata/bindings-loader.test.d.ts +0 -5
- package/dist/metadata/bindings-loader.test.d.ts.map +0 -1
- package/dist/metadata/bindings-loader.test.js +0 -117
- package/dist/metadata/bindings-loader.test.js.map +0 -1
- package/dist/metadata/index.d.ts +0 -8
- package/dist/metadata/index.d.ts.map +0 -1
- package/dist/metadata/index.js +0 -7
- package/dist/metadata/index.js.map +0 -1
- package/dist/metadata/library-loader.d.ts +0 -42
- package/dist/metadata/library-loader.d.ts.map +0 -1
- package/dist/metadata/library-loader.js +0 -126
- package/dist/metadata/library-loader.js.map +0 -1
- package/dist/metadata/loader.d.ts +0 -26
- package/dist/metadata/loader.d.ts.map +0 -1
- package/dist/metadata/loader.js +0 -333
- package/dist/metadata/loader.js.map +0 -1
- package/dist/metadata/loader.test.d.ts +0 -5
- package/dist/metadata/loader.test.d.ts.map +0 -1
- package/dist/metadata/loader.test.js +0 -119
- package/dist/metadata/loader.test.js.map +0 -1
- package/dist/resolver/naming-policy.d.ts +0 -20
- package/dist/resolver/naming-policy.d.ts.map +0 -1
- package/dist/resolver/naming-policy.js +0 -40
- package/dist/resolver/naming-policy.js.map +0 -1
- package/dist/types/bindings.d.ts +0 -153
- package/dist/types/bindings.d.ts.map +0 -1
- package/dist/types/bindings.js +0 -14
- package/dist/types/bindings.js.map +0 -1
- package/dist/types/metadata.d.ts +0 -196
- package/dist/types/metadata.d.ts.map +0 -1
- package/dist/types/metadata.js +0 -10
- package/dist/types/metadata.js.map +0 -1
- package/dist/types/nested-types.d.ts +0 -111
- package/dist/types/nested-types.d.ts.map +0 -1
- package/dist/types/nested-types.js +0 -176
- package/dist/types/nested-types.js.map +0 -1
- package/dist/types/nested-types.test.d.ts +0 -5
- package/dist/types/nested-types.test.d.ts.map +0 -1
- package/dist/types/nested-types.test.js +0 -135
- package/dist/types/nested-types.test.js.map +0 -1
- package/dist/types/ref-parameters.d.ts +0 -123
- package/dist/types/ref-parameters.d.ts.map +0 -1
- package/dist/types/ref-parameters.js +0 -203
- package/dist/types/ref-parameters.js.map +0 -1
- package/dist/types/ref-parameters.test.d.ts +0 -5
- package/dist/types/ref-parameters.test.d.ts.map +0 -1
- package/dist/types/ref-parameters.test.js +0 -147
- package/dist/types/ref-parameters.test.js.map +0 -1
|
@@ -70,6 +70,15 @@ const getGeneratorBody = (module) => {
|
|
|
70
70
|
}
|
|
71
71
|
return [];
|
|
72
72
|
};
|
|
73
|
+
const getTempNameFromSingleDeclarator = (stmt) => {
|
|
74
|
+
expect(stmt.kind).to.equal("variableDeclaration");
|
|
75
|
+
const decl = stmt
|
|
76
|
+
.declarations[0];
|
|
77
|
+
expect(decl?.name.kind).to.equal("identifierPattern");
|
|
78
|
+
return (decl?.name ?? {
|
|
79
|
+
name: "",
|
|
80
|
+
}).name;
|
|
81
|
+
};
|
|
73
82
|
describe("Yield Lowering Pass", () => {
|
|
74
83
|
describe("Basic Yield Transformation", () => {
|
|
75
84
|
it("should transform simple yield expr into yieldStatement", () => {
|
|
@@ -185,222 +194,1344 @@ describe("Yield Lowering Pass", () => {
|
|
|
185
194
|
expression: {
|
|
186
195
|
kind: "assignment",
|
|
187
196
|
operator: "=",
|
|
188
|
-
left: { kind: "identifierPattern", name: "x" },
|
|
189
|
-
right: createYield({ kind: "literal", value: 5 }),
|
|
197
|
+
left: { kind: "identifierPattern", name: "x" },
|
|
198
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
]);
|
|
202
|
+
const result = runYieldLoweringPass([module]);
|
|
203
|
+
expect(result.ok).to.be.true;
|
|
204
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
205
|
+
const yieldStmt = body[0];
|
|
206
|
+
expect(yieldStmt.kind).to.equal("yieldStatement");
|
|
207
|
+
expect(yieldStmt.receiveTarget?.kind).to.equal("identifierPattern");
|
|
208
|
+
});
|
|
209
|
+
it("should transform compound assignment with yield", () => {
|
|
210
|
+
const module = createGeneratorModule([
|
|
211
|
+
{
|
|
212
|
+
kind: "expressionStatement",
|
|
213
|
+
expression: {
|
|
214
|
+
kind: "assignment",
|
|
215
|
+
operator: "+=",
|
|
216
|
+
left: { kind: "identifierPattern", name: "x" },
|
|
217
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
]);
|
|
221
|
+
const result = runYieldLoweringPass([module]);
|
|
222
|
+
expect(result.ok).to.be.true;
|
|
223
|
+
expect(result.diagnostics).to.have.length(0);
|
|
224
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
225
|
+
expect(body).to.have.length(2);
|
|
226
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
227
|
+
expect(body[1]?.kind).to.equal("expressionStatement");
|
|
228
|
+
const assignmentStmt = body[1];
|
|
229
|
+
expect(assignmentStmt.expression.kind).to.equal("assignment");
|
|
230
|
+
if (assignmentStmt.expression.kind === "assignment") {
|
|
231
|
+
expect(assignmentStmt.expression.operator).to.equal("+=");
|
|
232
|
+
expect(assignmentStmt.expression.right.kind).to.equal("identifier");
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
it("should transform compound assignment to member target with yield", () => {
|
|
236
|
+
const module = createGeneratorModule([
|
|
237
|
+
{
|
|
238
|
+
kind: "expressionStatement",
|
|
239
|
+
expression: {
|
|
240
|
+
kind: "assignment",
|
|
241
|
+
operator: "+=",
|
|
242
|
+
left: {
|
|
243
|
+
kind: "memberAccess",
|
|
244
|
+
object: { kind: "identifier", name: "obj" },
|
|
245
|
+
property: "count",
|
|
246
|
+
isOptional: false,
|
|
247
|
+
isComputed: false,
|
|
248
|
+
},
|
|
249
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
]);
|
|
253
|
+
const result = runYieldLoweringPass([module]);
|
|
254
|
+
expect(result.ok).to.be.true;
|
|
255
|
+
expect(result.diagnostics).to.have.length(0);
|
|
256
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
257
|
+
expect(body).to.have.length(3);
|
|
258
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
259
|
+
expect(body[1]?.kind).to.equal("yieldStatement");
|
|
260
|
+
expect(body[2]?.kind).to.equal("expressionStatement");
|
|
261
|
+
const assignmentStmt = body[2];
|
|
262
|
+
expect(assignmentStmt.expression.kind).to.equal("assignment");
|
|
263
|
+
if (assignmentStmt.expression.kind === "assignment") {
|
|
264
|
+
expect(assignmentStmt.expression.left.kind).to.equal("memberAccess");
|
|
265
|
+
if (assignmentStmt.expression.left.kind === "memberAccess") {
|
|
266
|
+
expect(assignmentStmt.expression.left.object.kind).to.equal("identifier");
|
|
267
|
+
expect(assignmentStmt.expression.left.property).to.equal("count");
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
it("should transform compound assignment to computed member target with yield", () => {
|
|
272
|
+
const module = createGeneratorModule([
|
|
273
|
+
{
|
|
274
|
+
kind: "expressionStatement",
|
|
275
|
+
expression: {
|
|
276
|
+
kind: "assignment",
|
|
277
|
+
operator: "+=",
|
|
278
|
+
left: {
|
|
279
|
+
kind: "memberAccess",
|
|
280
|
+
object: { kind: "identifier", name: "obj" },
|
|
281
|
+
property: { kind: "identifier", name: "key" },
|
|
282
|
+
isOptional: false,
|
|
283
|
+
isComputed: true,
|
|
284
|
+
},
|
|
285
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
]);
|
|
289
|
+
const result = runYieldLoweringPass([module]);
|
|
290
|
+
expect(result.ok).to.be.true;
|
|
291
|
+
expect(result.diagnostics).to.have.length(0);
|
|
292
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
293
|
+
expect(body).to.have.length(4);
|
|
294
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
295
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
296
|
+
expect(body[2]?.kind).to.equal("yieldStatement");
|
|
297
|
+
expect(body[3]?.kind).to.equal("expressionStatement");
|
|
298
|
+
});
|
|
299
|
+
it("should transform compound assignment when target evaluation contains yield", () => {
|
|
300
|
+
const module = createGeneratorModule([
|
|
301
|
+
{
|
|
302
|
+
kind: "expressionStatement",
|
|
303
|
+
expression: {
|
|
304
|
+
kind: "assignment",
|
|
305
|
+
operator: "+=",
|
|
306
|
+
left: {
|
|
307
|
+
kind: "memberAccess",
|
|
308
|
+
object: createYield({ kind: "identifier", name: "obj" }),
|
|
309
|
+
property: "count",
|
|
310
|
+
isOptional: false,
|
|
311
|
+
isComputed: false,
|
|
312
|
+
},
|
|
313
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
]);
|
|
317
|
+
const result = runYieldLoweringPass([module]);
|
|
318
|
+
expect(result.ok).to.be.true;
|
|
319
|
+
expect(result.diagnostics).to.have.length(0);
|
|
320
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
321
|
+
expect(body).to.have.length(4);
|
|
322
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
323
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
324
|
+
expect(body[2]?.kind).to.equal("yieldStatement");
|
|
325
|
+
expect(body[3]?.kind).to.equal("expressionStatement");
|
|
326
|
+
});
|
|
327
|
+
it("should transform compound assignment when computed property contains yield", () => {
|
|
328
|
+
const module = createGeneratorModule([
|
|
329
|
+
{
|
|
330
|
+
kind: "expressionStatement",
|
|
331
|
+
expression: {
|
|
332
|
+
kind: "assignment",
|
|
333
|
+
operator: "+=",
|
|
334
|
+
left: {
|
|
335
|
+
kind: "memberAccess",
|
|
336
|
+
object: { kind: "identifier", name: "obj" },
|
|
337
|
+
property: createYield({ kind: "identifier", name: "key" }),
|
|
338
|
+
isOptional: false,
|
|
339
|
+
isComputed: true,
|
|
340
|
+
},
|
|
341
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
]);
|
|
345
|
+
const result = runYieldLoweringPass([module]);
|
|
346
|
+
expect(result.ok).to.be.true;
|
|
347
|
+
expect(result.diagnostics).to.have.length(0);
|
|
348
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
349
|
+
expect(body).to.have.length(5);
|
|
350
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
351
|
+
expect(body[1]?.kind).to.equal("yieldStatement");
|
|
352
|
+
expect(body[2]?.kind).to.equal("variableDeclaration");
|
|
353
|
+
expect(body[3]?.kind).to.equal("yieldStatement");
|
|
354
|
+
expect(body[4]?.kind).to.equal("expressionStatement");
|
|
355
|
+
});
|
|
356
|
+
it("should transform assignment with identifier expression target", () => {
|
|
357
|
+
const module = createGeneratorModule([
|
|
358
|
+
{
|
|
359
|
+
kind: "expressionStatement",
|
|
360
|
+
expression: {
|
|
361
|
+
kind: "assignment",
|
|
362
|
+
operator: "=",
|
|
363
|
+
left: { kind: "identifier", name: "x" },
|
|
364
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
]);
|
|
368
|
+
const result = runYieldLoweringPass([module]);
|
|
369
|
+
expect(result.ok).to.be.true;
|
|
370
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
371
|
+
const yieldStmt = body[0];
|
|
372
|
+
expect(yieldStmt.kind).to.equal("yieldStatement");
|
|
373
|
+
expect(yieldStmt.receiveTarget?.kind).to.equal("identifierPattern");
|
|
374
|
+
expect(yieldStmt.receiveTarget.name).to.equal("x");
|
|
375
|
+
});
|
|
376
|
+
it("should transform assignment to member target with yield", () => {
|
|
377
|
+
const module = createGeneratorModule([
|
|
378
|
+
{
|
|
379
|
+
kind: "expressionStatement",
|
|
380
|
+
expression: {
|
|
381
|
+
kind: "assignment",
|
|
382
|
+
operator: "=",
|
|
383
|
+
left: {
|
|
384
|
+
kind: "memberAccess",
|
|
385
|
+
object: { kind: "identifier", name: "obj" },
|
|
386
|
+
property: "count",
|
|
387
|
+
isOptional: false,
|
|
388
|
+
isComputed: false,
|
|
389
|
+
},
|
|
390
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
]);
|
|
394
|
+
const result = runYieldLoweringPass([module]);
|
|
395
|
+
expect(result.ok).to.be.true;
|
|
396
|
+
expect(result.diagnostics).to.have.length(0);
|
|
397
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
398
|
+
expect(body).to.have.length(3);
|
|
399
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
400
|
+
expect(body[1]?.kind).to.equal("yieldStatement");
|
|
401
|
+
expect(body[2]?.kind).to.equal("expressionStatement");
|
|
402
|
+
});
|
|
403
|
+
it("should transform assignment to computed member target with yield", () => {
|
|
404
|
+
const module = createGeneratorModule([
|
|
405
|
+
{
|
|
406
|
+
kind: "expressionStatement",
|
|
407
|
+
expression: {
|
|
408
|
+
kind: "assignment",
|
|
409
|
+
operator: "=",
|
|
410
|
+
left: {
|
|
411
|
+
kind: "memberAccess",
|
|
412
|
+
object: { kind: "identifier", name: "obj" },
|
|
413
|
+
property: { kind: "identifier", name: "key" },
|
|
414
|
+
isOptional: false,
|
|
415
|
+
isComputed: true,
|
|
416
|
+
},
|
|
417
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
]);
|
|
421
|
+
const result = runYieldLoweringPass([module]);
|
|
422
|
+
expect(result.ok).to.be.true;
|
|
423
|
+
expect(result.diagnostics).to.have.length(0);
|
|
424
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
425
|
+
expect(body).to.have.length(4);
|
|
426
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
427
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
428
|
+
expect(body[2]?.kind).to.equal("yieldStatement");
|
|
429
|
+
expect(body[3]?.kind).to.equal("expressionStatement");
|
|
430
|
+
});
|
|
431
|
+
it("should transform assignment when target object contains yield", () => {
|
|
432
|
+
const module = createGeneratorModule([
|
|
433
|
+
{
|
|
434
|
+
kind: "expressionStatement",
|
|
435
|
+
expression: {
|
|
436
|
+
kind: "assignment",
|
|
437
|
+
operator: "=",
|
|
438
|
+
left: {
|
|
439
|
+
kind: "memberAccess",
|
|
440
|
+
object: createYield({ kind: "identifier", name: "obj" }),
|
|
441
|
+
property: "count",
|
|
442
|
+
isOptional: false,
|
|
443
|
+
isComputed: false,
|
|
444
|
+
},
|
|
445
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
446
|
+
},
|
|
447
|
+
},
|
|
448
|
+
]);
|
|
449
|
+
const result = runYieldLoweringPass([module]);
|
|
450
|
+
expect(result.ok).to.be.true;
|
|
451
|
+
expect(result.diagnostics).to.have.length(0);
|
|
452
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
453
|
+
expect(body).to.have.length(4);
|
|
454
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
455
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
456
|
+
expect(body[2]?.kind).to.equal("yieldStatement");
|
|
457
|
+
expect(body[3]?.kind).to.equal("expressionStatement");
|
|
458
|
+
});
|
|
459
|
+
it("should transform assignment when computed property contains yield", () => {
|
|
460
|
+
const module = createGeneratorModule([
|
|
461
|
+
{
|
|
462
|
+
kind: "expressionStatement",
|
|
463
|
+
expression: {
|
|
464
|
+
kind: "assignment",
|
|
465
|
+
operator: "=",
|
|
466
|
+
left: {
|
|
467
|
+
kind: "memberAccess",
|
|
468
|
+
object: { kind: "identifier", name: "obj" },
|
|
469
|
+
property: createYield({ kind: "identifier", name: "key" }),
|
|
470
|
+
isOptional: false,
|
|
471
|
+
isComputed: true,
|
|
472
|
+
},
|
|
473
|
+
right: createYield({ kind: "literal", value: 5 }),
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
]);
|
|
477
|
+
const result = runYieldLoweringPass([module]);
|
|
478
|
+
expect(result.ok).to.be.true;
|
|
479
|
+
expect(result.diagnostics).to.have.length(0);
|
|
480
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
481
|
+
expect(body).to.have.length(5);
|
|
482
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
483
|
+
expect(body[1]?.kind).to.equal("yieldStatement");
|
|
484
|
+
expect(body[2]?.kind).to.equal("variableDeclaration");
|
|
485
|
+
expect(body[3]?.kind).to.equal("yieldStatement");
|
|
486
|
+
expect(body[4]?.kind).to.equal("expressionStatement");
|
|
487
|
+
});
|
|
488
|
+
it("should transform assignment when target object and right expression both contain yield", () => {
|
|
489
|
+
const module = createGeneratorModule([
|
|
490
|
+
{
|
|
491
|
+
kind: "expressionStatement",
|
|
492
|
+
expression: {
|
|
493
|
+
kind: "assignment",
|
|
494
|
+
operator: "=",
|
|
495
|
+
left: {
|
|
496
|
+
kind: "memberAccess",
|
|
497
|
+
object: createYield({ kind: "identifier", name: "obj" }),
|
|
498
|
+
property: "count",
|
|
499
|
+
isOptional: false,
|
|
500
|
+
isComputed: false,
|
|
501
|
+
},
|
|
502
|
+
right: {
|
|
503
|
+
kind: "binary",
|
|
504
|
+
operator: "+",
|
|
505
|
+
left: createYield({ kind: "literal", value: 5 }),
|
|
506
|
+
right: { kind: "literal", value: 1 },
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
},
|
|
510
|
+
]);
|
|
511
|
+
const result = runYieldLoweringPass([module]);
|
|
512
|
+
expect(result.ok).to.be.true;
|
|
513
|
+
expect(result.diagnostics).to.have.length(0);
|
|
514
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
515
|
+
expect(body).to.have.length(4);
|
|
516
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
517
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
518
|
+
expect(body[2]?.kind).to.equal("yieldStatement");
|
|
519
|
+
expect(body[3]?.kind).to.equal("expressionStatement");
|
|
520
|
+
});
|
|
521
|
+
it("should transform assignment when computed property and right expression both contain yield", () => {
|
|
522
|
+
const module = createGeneratorModule([
|
|
523
|
+
{
|
|
524
|
+
kind: "expressionStatement",
|
|
525
|
+
expression: {
|
|
526
|
+
kind: "assignment",
|
|
527
|
+
operator: "=",
|
|
528
|
+
left: {
|
|
529
|
+
kind: "memberAccess",
|
|
530
|
+
object: { kind: "identifier", name: "obj" },
|
|
531
|
+
property: createYield({ kind: "identifier", name: "key" }),
|
|
532
|
+
isOptional: false,
|
|
533
|
+
isComputed: true,
|
|
534
|
+
},
|
|
535
|
+
right: {
|
|
536
|
+
kind: "binary",
|
|
537
|
+
operator: "+",
|
|
538
|
+
left: createYield({ kind: "literal", value: 5 }),
|
|
539
|
+
right: { kind: "literal", value: 1 },
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
]);
|
|
544
|
+
const result = runYieldLoweringPass([module]);
|
|
545
|
+
expect(result.ok).to.be.true;
|
|
546
|
+
expect(result.diagnostics).to.have.length(0);
|
|
547
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
548
|
+
expect(body).to.have.length(5);
|
|
549
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
550
|
+
expect(body[1]?.kind).to.equal("yieldStatement");
|
|
551
|
+
expect(body[2]?.kind).to.equal("variableDeclaration");
|
|
552
|
+
expect(body[3]?.kind).to.equal("yieldStatement");
|
|
553
|
+
expect(body[4]?.kind).to.equal("expressionStatement");
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
describe("Destructuring Patterns", () => {
|
|
557
|
+
it("should transform array destructuring with yield", () => {
|
|
558
|
+
const module = createGeneratorModule([
|
|
559
|
+
{
|
|
560
|
+
kind: "variableDeclaration",
|
|
561
|
+
declarationKind: "const",
|
|
562
|
+
isExported: false,
|
|
563
|
+
declarations: [
|
|
564
|
+
{
|
|
565
|
+
kind: "variableDeclarator",
|
|
566
|
+
name: {
|
|
567
|
+
kind: "arrayPattern",
|
|
568
|
+
elements: [
|
|
569
|
+
{ pattern: { kind: "identifierPattern", name: "a" } },
|
|
570
|
+
{ pattern: { kind: "identifierPattern", name: "b" } },
|
|
571
|
+
],
|
|
572
|
+
},
|
|
573
|
+
initializer: createYield({ kind: "literal", value: null }),
|
|
574
|
+
},
|
|
575
|
+
],
|
|
576
|
+
},
|
|
577
|
+
]);
|
|
578
|
+
const result = runYieldLoweringPass([module]);
|
|
579
|
+
expect(result.ok).to.be.true;
|
|
580
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
581
|
+
const yieldStmt = body[0];
|
|
582
|
+
expect(yieldStmt.receiveTarget?.kind).to.equal("arrayPattern");
|
|
583
|
+
});
|
|
584
|
+
it("should transform object destructuring with yield", () => {
|
|
585
|
+
const module = createGeneratorModule([
|
|
586
|
+
{
|
|
587
|
+
kind: "variableDeclaration",
|
|
588
|
+
declarationKind: "const",
|
|
589
|
+
isExported: false,
|
|
590
|
+
declarations: [
|
|
591
|
+
{
|
|
592
|
+
kind: "variableDeclarator",
|
|
593
|
+
name: {
|
|
594
|
+
kind: "objectPattern",
|
|
595
|
+
properties: [
|
|
596
|
+
{
|
|
597
|
+
kind: "property",
|
|
598
|
+
key: "x",
|
|
599
|
+
value: { kind: "identifierPattern", name: "x" },
|
|
600
|
+
shorthand: true,
|
|
601
|
+
},
|
|
602
|
+
],
|
|
603
|
+
},
|
|
604
|
+
initializer: createYield({ kind: "literal", value: null }),
|
|
605
|
+
},
|
|
606
|
+
],
|
|
607
|
+
},
|
|
608
|
+
]);
|
|
609
|
+
const result = runYieldLoweringPass([module]);
|
|
610
|
+
expect(result.ok).to.be.true;
|
|
611
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
612
|
+
const yieldStmt = body[0];
|
|
613
|
+
expect(yieldStmt.receiveTarget?.kind).to.equal("objectPattern");
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
describe("Unsupported Patterns (TSN6101)", () => {
|
|
617
|
+
it("should lower yield inside member-access assignment target chains", () => {
|
|
618
|
+
const module = createGeneratorModule([
|
|
619
|
+
{
|
|
620
|
+
kind: "expressionStatement",
|
|
621
|
+
expression: {
|
|
622
|
+
kind: "assignment",
|
|
623
|
+
operator: "=",
|
|
624
|
+
left: {
|
|
625
|
+
kind: "memberAccess",
|
|
626
|
+
object: {
|
|
627
|
+
kind: "assignment",
|
|
628
|
+
operator: "=",
|
|
629
|
+
left: {
|
|
630
|
+
kind: "memberAccess",
|
|
631
|
+
object: createYield({ kind: "identifier", name: "tmpObj" }),
|
|
632
|
+
property: "inner",
|
|
633
|
+
isOptional: false,
|
|
634
|
+
isComputed: false,
|
|
635
|
+
},
|
|
636
|
+
right: { kind: "literal", value: 1 },
|
|
637
|
+
},
|
|
638
|
+
property: "count",
|
|
639
|
+
isOptional: false,
|
|
640
|
+
isComputed: false,
|
|
641
|
+
},
|
|
642
|
+
right: { kind: "literal", value: 2 },
|
|
643
|
+
},
|
|
644
|
+
},
|
|
645
|
+
]);
|
|
646
|
+
const result = runYieldLoweringPass([module]);
|
|
647
|
+
expect(result.ok).to.be.true;
|
|
648
|
+
expect(result.diagnostics).to.have.length(0);
|
|
649
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
650
|
+
expect(body).to.have.length(3);
|
|
651
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
652
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
653
|
+
expect(body[2]?.kind).to.equal("expressionStatement");
|
|
654
|
+
const finalExpr = body[2].expression;
|
|
655
|
+
expect(finalExpr.kind).to.equal("assignment");
|
|
656
|
+
if (finalExpr.kind === "assignment") {
|
|
657
|
+
expect(finalExpr.left.kind).to.equal("memberAccess");
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
it("should emit TSN6101 when yield appears in a non-lowerable assignment target", () => {
|
|
661
|
+
const module = createGeneratorModule([
|
|
662
|
+
{
|
|
663
|
+
kind: "expressionStatement",
|
|
664
|
+
expression: {
|
|
665
|
+
kind: "assignment",
|
|
666
|
+
operator: "=",
|
|
667
|
+
left: {
|
|
668
|
+
kind: "binary",
|
|
669
|
+
operator: "+",
|
|
670
|
+
left: createYield({ kind: "identifier", name: "lhs" }),
|
|
671
|
+
right: { kind: "literal", value: 1 },
|
|
672
|
+
},
|
|
673
|
+
right: { kind: "literal", value: 2 },
|
|
674
|
+
},
|
|
675
|
+
},
|
|
676
|
+
]);
|
|
677
|
+
const result = runYieldLoweringPass([module]);
|
|
678
|
+
expect(result.ok).to.be.false;
|
|
679
|
+
expect(result.diagnostics.length).to.be.greaterThan(0);
|
|
680
|
+
expect(result.diagnostics[0]?.code).to.equal("TSN6101");
|
|
681
|
+
});
|
|
682
|
+
it("should emit TSN6101 when yield appears in switch case test expression", () => {
|
|
683
|
+
const module = createGeneratorModule([
|
|
684
|
+
{
|
|
685
|
+
kind: "switchStatement",
|
|
686
|
+
expression: { kind: "identifier", name: "value" },
|
|
687
|
+
cases: [
|
|
688
|
+
{
|
|
689
|
+
kind: "switchCase",
|
|
690
|
+
test: createYield({ kind: "literal", value: 1 }),
|
|
691
|
+
statements: [{ kind: "breakStatement" }],
|
|
692
|
+
},
|
|
693
|
+
],
|
|
694
|
+
},
|
|
695
|
+
]);
|
|
696
|
+
const result = runYieldLoweringPass([module]);
|
|
697
|
+
expect(result.ok).to.be.false;
|
|
698
|
+
expect(result.diagnostics.length).to.be.greaterThan(0);
|
|
699
|
+
expect(result.diagnostics.some((d) => d.code === "TSN6101")).to.equal(true);
|
|
700
|
+
});
|
|
701
|
+
it("should transform yield in call argument", () => {
|
|
702
|
+
const module = createGeneratorModule([
|
|
703
|
+
{
|
|
704
|
+
kind: "expressionStatement",
|
|
705
|
+
expression: {
|
|
706
|
+
kind: "call",
|
|
707
|
+
callee: { kind: "identifier", name: "foo" },
|
|
708
|
+
arguments: [createYield({ kind: "literal", value: 1 })],
|
|
709
|
+
isOptional: false,
|
|
710
|
+
},
|
|
711
|
+
},
|
|
712
|
+
]);
|
|
713
|
+
const result = runYieldLoweringPass([module]);
|
|
714
|
+
expect(result.ok).to.be.true;
|
|
715
|
+
expect(result.diagnostics).to.have.length(0);
|
|
716
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
717
|
+
expect(body).to.have.length(2);
|
|
718
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
719
|
+
expect(body[1]?.kind).to.equal("expressionStatement");
|
|
720
|
+
});
|
|
721
|
+
it("should transform nested yield in initializer", () => {
|
|
722
|
+
const module = createGeneratorModule([
|
|
723
|
+
{
|
|
724
|
+
kind: "variableDeclaration",
|
|
725
|
+
declarationKind: "const",
|
|
726
|
+
isExported: false,
|
|
727
|
+
declarations: [
|
|
728
|
+
{
|
|
729
|
+
kind: "variableDeclarator",
|
|
730
|
+
name: { kind: "identifierPattern", name: "x" },
|
|
731
|
+
type: { kind: "primitiveType", name: "number" },
|
|
732
|
+
initializer: {
|
|
733
|
+
kind: "binary",
|
|
734
|
+
operator: "+",
|
|
735
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
736
|
+
right: { kind: "literal", value: 2 },
|
|
737
|
+
},
|
|
738
|
+
},
|
|
739
|
+
],
|
|
740
|
+
},
|
|
741
|
+
]);
|
|
742
|
+
const result = runYieldLoweringPass([module]);
|
|
743
|
+
expect(result.ok).to.be.true;
|
|
744
|
+
expect(result.diagnostics).to.have.length(0);
|
|
745
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
746
|
+
expect(body).to.have.length(2);
|
|
747
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
748
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
749
|
+
});
|
|
750
|
+
it("should transform yield in conditional expression condition", () => {
|
|
751
|
+
const module = createGeneratorModule([
|
|
752
|
+
{
|
|
753
|
+
kind: "variableDeclaration",
|
|
754
|
+
declarationKind: "const",
|
|
755
|
+
isExported: false,
|
|
756
|
+
declarations: [
|
|
757
|
+
{
|
|
758
|
+
kind: "variableDeclarator",
|
|
759
|
+
name: { kind: "identifierPattern", name: "x" },
|
|
760
|
+
initializer: {
|
|
761
|
+
kind: "conditional",
|
|
762
|
+
condition: createYield({ kind: "literal", value: true }),
|
|
763
|
+
whenTrue: { kind: "literal", value: 1 },
|
|
764
|
+
whenFalse: { kind: "literal", value: 2 },
|
|
765
|
+
inferredType: { kind: "primitiveType", name: "number" },
|
|
766
|
+
},
|
|
767
|
+
},
|
|
768
|
+
],
|
|
769
|
+
},
|
|
770
|
+
]);
|
|
771
|
+
const result = runYieldLoweringPass([module]);
|
|
772
|
+
expect(result.ok).to.be.true;
|
|
773
|
+
expect(result.diagnostics).to.have.length(0);
|
|
774
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
775
|
+
expect(body).to.have.length(4);
|
|
776
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
777
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
778
|
+
expect(body[2]?.kind).to.equal("ifStatement");
|
|
779
|
+
expect(body[3]?.kind).to.equal("variableDeclaration");
|
|
780
|
+
});
|
|
781
|
+
it("should transform yield in conditional expression branches lazily", () => {
|
|
782
|
+
const module = createGeneratorModule([
|
|
783
|
+
{
|
|
784
|
+
kind: "variableDeclaration",
|
|
785
|
+
declarationKind: "const",
|
|
786
|
+
isExported: false,
|
|
787
|
+
declarations: [
|
|
788
|
+
{
|
|
789
|
+
kind: "variableDeclarator",
|
|
790
|
+
name: { kind: "identifierPattern", name: "x" },
|
|
791
|
+
initializer: {
|
|
792
|
+
kind: "conditional",
|
|
793
|
+
condition: { kind: "literal", value: true },
|
|
794
|
+
whenTrue: createYield({ kind: "literal", value: 1 }),
|
|
795
|
+
whenFalse: createYield({ kind: "literal", value: 2 }),
|
|
796
|
+
inferredType: { kind: "primitiveType", name: "number" },
|
|
797
|
+
},
|
|
798
|
+
},
|
|
799
|
+
],
|
|
800
|
+
},
|
|
801
|
+
]);
|
|
802
|
+
const result = runYieldLoweringPass([module]);
|
|
803
|
+
expect(result.ok).to.be.true;
|
|
804
|
+
expect(result.diagnostics).to.have.length(0);
|
|
805
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
806
|
+
expect(body).to.have.length(3);
|
|
807
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
808
|
+
expect(body[1]?.kind).to.equal("ifStatement");
|
|
809
|
+
expect(body[2]?.kind).to.equal("variableDeclaration");
|
|
810
|
+
const loweredIf = body[1];
|
|
811
|
+
expect(loweredIf.thenStatement.kind).to.equal("blockStatement");
|
|
812
|
+
expect(loweredIf.elseStatement?.kind).to.equal("blockStatement");
|
|
813
|
+
const thenStatements = loweredIf.thenStatement.kind === "blockStatement"
|
|
814
|
+
? loweredIf.thenStatement.statements
|
|
815
|
+
: [];
|
|
816
|
+
const elseStatements = loweredIf.elseStatement?.kind === "blockStatement"
|
|
817
|
+
? loweredIf.elseStatement.statements
|
|
818
|
+
: [];
|
|
819
|
+
expect(thenStatements[0]?.kind).to.equal("yieldStatement");
|
|
820
|
+
expect(thenStatements[1]?.kind).to.equal("expressionStatement");
|
|
821
|
+
expect(elseStatements[0]?.kind).to.equal("yieldStatement");
|
|
822
|
+
expect(elseStatements[1]?.kind).to.equal("expressionStatement");
|
|
823
|
+
});
|
|
824
|
+
it("should transform return yield expression into yield+generatorReturn", () => {
|
|
825
|
+
const module = createGeneratorModule([
|
|
826
|
+
{
|
|
827
|
+
kind: "returnStatement",
|
|
828
|
+
expression: createYield({ kind: "literal", value: 1 }),
|
|
829
|
+
},
|
|
830
|
+
]);
|
|
831
|
+
const result = runYieldLoweringPass([module]);
|
|
832
|
+
expect(result.ok).to.be.true;
|
|
833
|
+
expect(result.diagnostics).to.have.length(0);
|
|
834
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
835
|
+
expect(body).to.have.length(2);
|
|
836
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
837
|
+
expect(body[1]?.kind).to.equal("generatorReturnStatement");
|
|
838
|
+
});
|
|
839
|
+
it("should transform throw yield expression into yield+throw", () => {
|
|
840
|
+
const module = createGeneratorModule([
|
|
841
|
+
{
|
|
842
|
+
kind: "throwStatement",
|
|
843
|
+
expression: createYield({ kind: "identifier", name: "err" }),
|
|
844
|
+
},
|
|
845
|
+
]);
|
|
846
|
+
const result = runYieldLoweringPass([module]);
|
|
847
|
+
expect(result.ok).to.be.true;
|
|
848
|
+
expect(result.diagnostics).to.have.length(0);
|
|
849
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
850
|
+
expect(body).to.have.length(2);
|
|
851
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
852
|
+
expect(body[1]?.kind).to.equal("throwStatement");
|
|
853
|
+
});
|
|
854
|
+
it("should transform nested yield in return expression", () => {
|
|
855
|
+
const module = createGeneratorModule([
|
|
856
|
+
{
|
|
857
|
+
kind: "returnStatement",
|
|
858
|
+
expression: {
|
|
859
|
+
kind: "binary",
|
|
860
|
+
operator: "+",
|
|
861
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
862
|
+
right: { kind: "literal", value: 2 },
|
|
863
|
+
},
|
|
864
|
+
},
|
|
865
|
+
]);
|
|
866
|
+
const result = runYieldLoweringPass([module]);
|
|
867
|
+
expect(result.ok).to.be.true;
|
|
868
|
+
expect(result.diagnostics).to.have.length(0);
|
|
869
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
870
|
+
expect(body).to.have.length(2);
|
|
871
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
872
|
+
expect(body[1]?.kind).to.equal("generatorReturnStatement");
|
|
873
|
+
});
|
|
874
|
+
it("should transform for-loop assignment initializer with yield", () => {
|
|
875
|
+
const module = createGeneratorModule([
|
|
876
|
+
{
|
|
877
|
+
kind: "forStatement",
|
|
878
|
+
initializer: {
|
|
879
|
+
kind: "assignment",
|
|
880
|
+
operator: "=",
|
|
881
|
+
left: { kind: "identifierPattern", name: "x" },
|
|
882
|
+
right: createYield({ kind: "literal", value: 1 }),
|
|
883
|
+
},
|
|
884
|
+
condition: { kind: "literal", value: true },
|
|
885
|
+
body: { kind: "blockStatement", statements: [] },
|
|
886
|
+
},
|
|
887
|
+
]);
|
|
888
|
+
const result = runYieldLoweringPass([module]);
|
|
889
|
+
expect(result.ok).to.be.true;
|
|
890
|
+
expect(result.diagnostics).to.have.length(0);
|
|
891
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
892
|
+
expect(body).to.have.length(2);
|
|
893
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
894
|
+
expect(body[1]?.kind).to.equal("forStatement");
|
|
895
|
+
const loweredFor = body[1];
|
|
896
|
+
expect(loweredFor.initializer).to.equal(undefined);
|
|
897
|
+
});
|
|
898
|
+
it("should transform for-loop member assignment initializer with yield", () => {
|
|
899
|
+
const module = createGeneratorModule([
|
|
900
|
+
{
|
|
901
|
+
kind: "forStatement",
|
|
902
|
+
initializer: {
|
|
903
|
+
kind: "assignment",
|
|
904
|
+
operator: "=",
|
|
905
|
+
left: {
|
|
906
|
+
kind: "memberAccess",
|
|
907
|
+
object: { kind: "identifier", name: "obj" },
|
|
908
|
+
property: "count",
|
|
909
|
+
isOptional: false,
|
|
910
|
+
isComputed: false,
|
|
911
|
+
},
|
|
912
|
+
right: createYield({ kind: "literal", value: 1 }),
|
|
913
|
+
},
|
|
914
|
+
condition: { kind: "literal", value: true },
|
|
915
|
+
body: { kind: "blockStatement", statements: [] },
|
|
916
|
+
},
|
|
917
|
+
]);
|
|
918
|
+
const result = runYieldLoweringPass([module]);
|
|
919
|
+
expect(result.ok).to.be.true;
|
|
920
|
+
expect(result.diagnostics).to.have.length(0);
|
|
921
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
922
|
+
expect(body).to.have.length(4);
|
|
923
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
924
|
+
expect(body[1]?.kind).to.equal("yieldStatement");
|
|
925
|
+
expect(body[2]?.kind).to.equal("expressionStatement");
|
|
926
|
+
expect(body[3]?.kind).to.equal("forStatement");
|
|
927
|
+
const objectTempName = getTempNameFromSingleDeclarator(assertDefined(body[0]));
|
|
928
|
+
const receiveName = body[1].receiveTarget;
|
|
929
|
+
const assignExpr = body[2].expression;
|
|
930
|
+
expect(assignExpr.left.kind).to.equal("memberAccess");
|
|
931
|
+
const left = assignExpr.left;
|
|
932
|
+
expect(left.object.kind).to.equal("identifier");
|
|
933
|
+
expect(left.object.name).to.equal(objectTempName);
|
|
934
|
+
expect(left.property).to.equal("count");
|
|
935
|
+
expect(assignExpr.right.kind).to.equal("identifier");
|
|
936
|
+
expect(assignExpr.right.name).to.equal(receiveName.name);
|
|
937
|
+
const loweredFor = body[3];
|
|
938
|
+
expect(loweredFor.initializer).to.equal(undefined);
|
|
939
|
+
});
|
|
940
|
+
it("should transform for-loop computed member assignment initializer with yield", () => {
|
|
941
|
+
const module = createGeneratorModule([
|
|
942
|
+
{
|
|
943
|
+
kind: "forStatement",
|
|
944
|
+
initializer: {
|
|
945
|
+
kind: "assignment",
|
|
946
|
+
operator: "=",
|
|
947
|
+
left: {
|
|
948
|
+
kind: "memberAccess",
|
|
949
|
+
object: { kind: "identifier", name: "obj" },
|
|
950
|
+
property: { kind: "identifier", name: "key" },
|
|
951
|
+
isOptional: false,
|
|
952
|
+
isComputed: true,
|
|
953
|
+
},
|
|
954
|
+
right: createYield({ kind: "literal", value: 1 }),
|
|
955
|
+
},
|
|
956
|
+
condition: { kind: "literal", value: true },
|
|
957
|
+
body: { kind: "blockStatement", statements: [] },
|
|
958
|
+
},
|
|
959
|
+
]);
|
|
960
|
+
const result = runYieldLoweringPass([module]);
|
|
961
|
+
expect(result.ok).to.be.true;
|
|
962
|
+
expect(result.diagnostics).to.have.length(0);
|
|
963
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
964
|
+
expect(body).to.have.length(5);
|
|
965
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
966
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
967
|
+
expect(body[2]?.kind).to.equal("yieldStatement");
|
|
968
|
+
expect(body[3]?.kind).to.equal("expressionStatement");
|
|
969
|
+
expect(body[4]?.kind).to.equal("forStatement");
|
|
970
|
+
const objectTempName = getTempNameFromSingleDeclarator(assertDefined(body[0]));
|
|
971
|
+
const propertyTempName = getTempNameFromSingleDeclarator(assertDefined(body[1]));
|
|
972
|
+
const receiveName = body[2].receiveTarget;
|
|
973
|
+
const assignExpr = body[3].expression;
|
|
974
|
+
expect(assignExpr.left.kind).to.equal("memberAccess");
|
|
975
|
+
const left = assignExpr.left;
|
|
976
|
+
expect(left.object.kind).to.equal("identifier");
|
|
977
|
+
expect(left.object.name).to.equal(objectTempName);
|
|
978
|
+
expect(typeof left.property).to.not.equal("string");
|
|
979
|
+
expect(left.property.kind).to.equal("identifier");
|
|
980
|
+
expect(left.property.name).to.equal(propertyTempName);
|
|
981
|
+
expect(assignExpr.right.kind).to.equal("identifier");
|
|
982
|
+
expect(assignExpr.right.name).to.equal(receiveName.name);
|
|
983
|
+
const loweredFor = body[4];
|
|
984
|
+
expect(loweredFor.initializer).to.equal(undefined);
|
|
985
|
+
});
|
|
986
|
+
it("should transform for-loop member assignment initializer when object evaluation contains yield", () => {
|
|
987
|
+
const module = createGeneratorModule([
|
|
988
|
+
{
|
|
989
|
+
kind: "forStatement",
|
|
990
|
+
initializer: {
|
|
991
|
+
kind: "assignment",
|
|
992
|
+
operator: "=",
|
|
993
|
+
left: {
|
|
994
|
+
kind: "memberAccess",
|
|
995
|
+
object: createYield({ kind: "identifier", name: "obj" }),
|
|
996
|
+
property: "count",
|
|
997
|
+
isOptional: false,
|
|
998
|
+
isComputed: false,
|
|
999
|
+
},
|
|
1000
|
+
right: createYield({ kind: "literal", value: 1 }),
|
|
1001
|
+
},
|
|
1002
|
+
condition: { kind: "literal", value: true },
|
|
1003
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1004
|
+
},
|
|
1005
|
+
]);
|
|
1006
|
+
const result = runYieldLoweringPass([module]);
|
|
1007
|
+
expect(result.ok).to.be.true;
|
|
1008
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1009
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1010
|
+
expect(body).to.have.length(5);
|
|
1011
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1012
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
1013
|
+
expect(body[2]?.kind).to.equal("yieldStatement");
|
|
1014
|
+
expect(body[3]?.kind).to.equal("expressionStatement");
|
|
1015
|
+
expect(body[4]?.kind).to.equal("forStatement");
|
|
1016
|
+
const objectTempName = getTempNameFromSingleDeclarator(assertDefined(body[1]));
|
|
1017
|
+
const objectYieldReceive = body[0].receiveTarget;
|
|
1018
|
+
const objectTempInit = body[1].declarations[0]?.initializer;
|
|
1019
|
+
expect(objectTempInit.kind).to.equal("identifier");
|
|
1020
|
+
expect(objectTempInit.name).to.equal(objectYieldReceive.name);
|
|
1021
|
+
const assignExpr = body[3].expression;
|
|
1022
|
+
expect(assignExpr.left.kind).to.equal("memberAccess");
|
|
1023
|
+
const left = assignExpr.left;
|
|
1024
|
+
expect(left.object.kind).to.equal("identifier");
|
|
1025
|
+
expect(left.object.name).to.equal(objectTempName);
|
|
1026
|
+
});
|
|
1027
|
+
it("should transform for-loop member assignment initializer when computed property contains yield", () => {
|
|
1028
|
+
const module = createGeneratorModule([
|
|
1029
|
+
{
|
|
1030
|
+
kind: "forStatement",
|
|
1031
|
+
initializer: {
|
|
1032
|
+
kind: "assignment",
|
|
1033
|
+
operator: "=",
|
|
1034
|
+
left: {
|
|
1035
|
+
kind: "memberAccess",
|
|
1036
|
+
object: { kind: "identifier", name: "obj" },
|
|
1037
|
+
property: createYield({ kind: "identifier", name: "key" }),
|
|
1038
|
+
isOptional: false,
|
|
1039
|
+
isComputed: true,
|
|
1040
|
+
},
|
|
1041
|
+
right: createYield({ kind: "literal", value: 1 }),
|
|
1042
|
+
},
|
|
1043
|
+
condition: { kind: "literal", value: true },
|
|
1044
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1045
|
+
},
|
|
1046
|
+
]);
|
|
1047
|
+
const result = runYieldLoweringPass([module]);
|
|
1048
|
+
expect(result.ok).to.be.true;
|
|
1049
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1050
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1051
|
+
expect(body).to.have.length(6);
|
|
1052
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
1053
|
+
expect(body[1]?.kind).to.equal("yieldStatement");
|
|
1054
|
+
expect(body[2]?.kind).to.equal("variableDeclaration");
|
|
1055
|
+
expect(body[3]?.kind).to.equal("yieldStatement");
|
|
1056
|
+
expect(body[4]?.kind).to.equal("expressionStatement");
|
|
1057
|
+
expect(body[5]?.kind).to.equal("forStatement");
|
|
1058
|
+
const objectTempName = getTempNameFromSingleDeclarator(assertDefined(body[0]));
|
|
1059
|
+
const propertyTempName = getTempNameFromSingleDeclarator(assertDefined(body[2]));
|
|
1060
|
+
const propertyYieldReceive = body[1].receiveTarget;
|
|
1061
|
+
const propertyTempInit = body[2].declarations[0]?.initializer;
|
|
1062
|
+
expect(propertyTempInit.kind).to.equal("identifier");
|
|
1063
|
+
expect(propertyTempInit.name).to.equal(propertyYieldReceive.name);
|
|
1064
|
+
const assignExpr = body[4].expression;
|
|
1065
|
+
expect(assignExpr.left.kind).to.equal("memberAccess");
|
|
1066
|
+
const left = assignExpr.left;
|
|
1067
|
+
expect(left.object.kind).to.equal("identifier");
|
|
1068
|
+
expect(left.object.name).to.equal(objectTempName);
|
|
1069
|
+
expect(typeof left.property).to.not.equal("string");
|
|
1070
|
+
expect(left.property.kind).to.equal("identifier");
|
|
1071
|
+
expect(left.property.name).to.equal(propertyTempName);
|
|
1072
|
+
});
|
|
1073
|
+
it("should transform for-loop member assignment initializer when target object and value expression both contain yield", () => {
|
|
1074
|
+
const module = createGeneratorModule([
|
|
1075
|
+
{
|
|
1076
|
+
kind: "forStatement",
|
|
1077
|
+
initializer: {
|
|
1078
|
+
kind: "assignment",
|
|
1079
|
+
operator: "=",
|
|
1080
|
+
left: {
|
|
1081
|
+
kind: "memberAccess",
|
|
1082
|
+
object: createYield({ kind: "identifier", name: "obj" }),
|
|
1083
|
+
property: "count",
|
|
1084
|
+
isOptional: false,
|
|
1085
|
+
isComputed: false,
|
|
1086
|
+
},
|
|
1087
|
+
right: {
|
|
1088
|
+
kind: "binary",
|
|
1089
|
+
operator: "+",
|
|
1090
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1091
|
+
right: { kind: "literal", value: 2 },
|
|
1092
|
+
},
|
|
1093
|
+
},
|
|
1094
|
+
condition: { kind: "literal", value: true },
|
|
1095
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1096
|
+
},
|
|
1097
|
+
]);
|
|
1098
|
+
const result = runYieldLoweringPass([module]);
|
|
1099
|
+
expect(result.ok).to.be.true;
|
|
1100
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1101
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1102
|
+
expect(body).to.have.length(5);
|
|
1103
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1104
|
+
expect(body[1]?.kind).to.equal("variableDeclaration");
|
|
1105
|
+
expect(body[2]?.kind).to.equal("yieldStatement");
|
|
1106
|
+
expect(body[3]?.kind).to.equal("expressionStatement");
|
|
1107
|
+
expect(body[4]?.kind).to.equal("forStatement");
|
|
1108
|
+
});
|
|
1109
|
+
it("should transform for-loop member assignment initializer when computed property and value expression both contain yield", () => {
|
|
1110
|
+
const module = createGeneratorModule([
|
|
1111
|
+
{
|
|
1112
|
+
kind: "forStatement",
|
|
1113
|
+
initializer: {
|
|
1114
|
+
kind: "assignment",
|
|
1115
|
+
operator: "=",
|
|
1116
|
+
left: {
|
|
1117
|
+
kind: "memberAccess",
|
|
1118
|
+
object: { kind: "identifier", name: "obj" },
|
|
1119
|
+
property: createYield({ kind: "identifier", name: "key" }),
|
|
1120
|
+
isOptional: false,
|
|
1121
|
+
isComputed: true,
|
|
1122
|
+
},
|
|
1123
|
+
right: {
|
|
1124
|
+
kind: "binary",
|
|
1125
|
+
operator: "+",
|
|
1126
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1127
|
+
right: { kind: "literal", value: 2 },
|
|
1128
|
+
},
|
|
1129
|
+
},
|
|
1130
|
+
condition: { kind: "literal", value: true },
|
|
1131
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1132
|
+
},
|
|
1133
|
+
]);
|
|
1134
|
+
const result = runYieldLoweringPass([module]);
|
|
1135
|
+
expect(result.ok).to.be.true;
|
|
1136
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1137
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1138
|
+
expect(body).to.have.length(6);
|
|
1139
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
1140
|
+
expect(body[1]?.kind).to.equal("yieldStatement");
|
|
1141
|
+
expect(body[2]?.kind).to.equal("variableDeclaration");
|
|
1142
|
+
expect(body[3]?.kind).to.equal("yieldStatement");
|
|
1143
|
+
expect(body[4]?.kind).to.equal("expressionStatement");
|
|
1144
|
+
expect(body[5]?.kind).to.equal("forStatement");
|
|
1145
|
+
});
|
|
1146
|
+
it("should transform nested yield in for-loop assignment initializer", () => {
|
|
1147
|
+
const module = createGeneratorModule([
|
|
1148
|
+
{
|
|
1149
|
+
kind: "forStatement",
|
|
1150
|
+
initializer: {
|
|
1151
|
+
kind: "assignment",
|
|
1152
|
+
operator: "=",
|
|
1153
|
+
left: { kind: "identifierPattern", name: "x" },
|
|
1154
|
+
right: {
|
|
1155
|
+
kind: "binary",
|
|
1156
|
+
operator: "+",
|
|
1157
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1158
|
+
right: { kind: "literal", value: 2 },
|
|
1159
|
+
},
|
|
1160
|
+
},
|
|
1161
|
+
condition: { kind: "literal", value: true },
|
|
1162
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1163
|
+
},
|
|
1164
|
+
]);
|
|
1165
|
+
const result = runYieldLoweringPass([module]);
|
|
1166
|
+
expect(result.ok).to.be.true;
|
|
1167
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1168
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1169
|
+
expect(body).to.have.length(2);
|
|
1170
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1171
|
+
expect(body[1]?.kind).to.equal("forStatement");
|
|
1172
|
+
const loweredFor = body[1];
|
|
1173
|
+
expect(loweredFor.initializer?.kind).to.equal("assignment");
|
|
1174
|
+
});
|
|
1175
|
+
it("should transform direct yield in for-loop declaration initializer", () => {
|
|
1176
|
+
const module = createGeneratorModule([
|
|
1177
|
+
{
|
|
1178
|
+
kind: "forStatement",
|
|
1179
|
+
initializer: {
|
|
1180
|
+
kind: "variableDeclaration",
|
|
1181
|
+
declarationKind: "let",
|
|
1182
|
+
isExported: false,
|
|
1183
|
+
declarations: [
|
|
1184
|
+
{
|
|
1185
|
+
kind: "variableDeclarator",
|
|
1186
|
+
name: { kind: "identifierPattern", name: "x" },
|
|
1187
|
+
type: { kind: "primitiveType", name: "number" },
|
|
1188
|
+
initializer: createYield({ kind: "literal", value: 1 }),
|
|
1189
|
+
},
|
|
1190
|
+
],
|
|
1191
|
+
},
|
|
1192
|
+
condition: { kind: "literal", value: true },
|
|
1193
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1194
|
+
},
|
|
1195
|
+
]);
|
|
1196
|
+
const result = runYieldLoweringPass([module]);
|
|
1197
|
+
expect(result.ok).to.be.true;
|
|
1198
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1199
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1200
|
+
expect(body).to.have.length(2);
|
|
1201
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1202
|
+
expect(body[1]?.kind).to.equal("forStatement");
|
|
1203
|
+
const loweredFor = body[1];
|
|
1204
|
+
expect(loweredFor.initializer?.kind).to.equal("variableDeclaration");
|
|
1205
|
+
const initDecl = loweredFor.initializer;
|
|
1206
|
+
expect(initDecl.declarations[0]?.initializer?.kind).to.equal("identifier");
|
|
1207
|
+
});
|
|
1208
|
+
it("should transform nested yield in for-loop declaration initializer", () => {
|
|
1209
|
+
const module = createGeneratorModule([
|
|
1210
|
+
{
|
|
1211
|
+
kind: "forStatement",
|
|
1212
|
+
initializer: {
|
|
1213
|
+
kind: "variableDeclaration",
|
|
1214
|
+
declarationKind: "let",
|
|
1215
|
+
isExported: false,
|
|
1216
|
+
declarations: [
|
|
1217
|
+
{
|
|
1218
|
+
kind: "variableDeclarator",
|
|
1219
|
+
name: { kind: "identifierPattern", name: "x" },
|
|
1220
|
+
type: { kind: "primitiveType", name: "number" },
|
|
1221
|
+
initializer: {
|
|
1222
|
+
kind: "binary",
|
|
1223
|
+
operator: "+",
|
|
1224
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1225
|
+
right: { kind: "literal", value: 2 },
|
|
1226
|
+
},
|
|
1227
|
+
},
|
|
1228
|
+
],
|
|
1229
|
+
},
|
|
1230
|
+
condition: { kind: "literal", value: true },
|
|
1231
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1232
|
+
},
|
|
1233
|
+
]);
|
|
1234
|
+
const result = runYieldLoweringPass([module]);
|
|
1235
|
+
expect(result.ok).to.be.true;
|
|
1236
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1237
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1238
|
+
expect(body).to.have.length(2);
|
|
1239
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1240
|
+
expect(body[1]?.kind).to.equal("forStatement");
|
|
1241
|
+
const loweredFor = body[1];
|
|
1242
|
+
expect(loweredFor.initializer?.kind).to.equal("variableDeclaration");
|
|
1243
|
+
const initDecl = loweredFor.initializer;
|
|
1244
|
+
expect(initDecl.declarations[0]?.initializer?.kind).to.equal("binary");
|
|
1245
|
+
});
|
|
1246
|
+
it("should transform nested yield in for loop condition", () => {
|
|
1247
|
+
const module = createGeneratorModule([
|
|
1248
|
+
{
|
|
1249
|
+
kind: "forStatement",
|
|
1250
|
+
condition: {
|
|
1251
|
+
kind: "logical",
|
|
1252
|
+
operator: "&&",
|
|
1253
|
+
left: createYield({ kind: "literal", value: true }),
|
|
1254
|
+
right: { kind: "literal", value: true },
|
|
1255
|
+
},
|
|
1256
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1257
|
+
},
|
|
1258
|
+
]);
|
|
1259
|
+
const result = runYieldLoweringPass([module]);
|
|
1260
|
+
expect(result.ok).to.be.true;
|
|
1261
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1262
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1263
|
+
expect(body).to.have.length(1);
|
|
1264
|
+
expect(body[0]?.kind).to.equal("forStatement");
|
|
1265
|
+
});
|
|
1266
|
+
it("should transform nested yield in for loop update", () => {
|
|
1267
|
+
const module = createGeneratorModule([
|
|
1268
|
+
{
|
|
1269
|
+
kind: "forStatement",
|
|
1270
|
+
condition: { kind: "literal", value: true },
|
|
1271
|
+
update: {
|
|
1272
|
+
kind: "assignment",
|
|
1273
|
+
operator: "=",
|
|
1274
|
+
left: { kind: "identifierPattern", name: "i" },
|
|
1275
|
+
right: {
|
|
1276
|
+
kind: "binary",
|
|
1277
|
+
operator: "+",
|
|
1278
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1279
|
+
right: { kind: "literal", value: 2 },
|
|
1280
|
+
},
|
|
190
1281
|
},
|
|
1282
|
+
body: { kind: "blockStatement", statements: [] },
|
|
191
1283
|
},
|
|
192
1284
|
]);
|
|
193
1285
|
const result = runYieldLoweringPass([module]);
|
|
194
1286
|
expect(result.ok).to.be.true;
|
|
1287
|
+
expect(result.diagnostics).to.have.length(0);
|
|
195
1288
|
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
196
|
-
|
|
197
|
-
expect(
|
|
198
|
-
expect(
|
|
1289
|
+
expect(body).to.have.length(2);
|
|
1290
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
1291
|
+
expect(body[1]?.kind).to.equal("forStatement");
|
|
199
1292
|
});
|
|
200
|
-
it("should
|
|
1293
|
+
it("should transform nested yield in if condition", () => {
|
|
201
1294
|
const module = createGeneratorModule([
|
|
202
1295
|
{
|
|
203
|
-
kind: "
|
|
204
|
-
|
|
205
|
-
kind: "
|
|
206
|
-
operator: "
|
|
207
|
-
left: { kind: "
|
|
208
|
-
right:
|
|
1296
|
+
kind: "ifStatement",
|
|
1297
|
+
condition: {
|
|
1298
|
+
kind: "binary",
|
|
1299
|
+
operator: "+",
|
|
1300
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1301
|
+
right: { kind: "literal", value: 2 },
|
|
209
1302
|
},
|
|
1303
|
+
thenStatement: { kind: "blockStatement", statements: [] },
|
|
210
1304
|
},
|
|
211
1305
|
]);
|
|
212
1306
|
const result = runYieldLoweringPass([module]);
|
|
213
|
-
expect(result.ok).to.be.
|
|
214
|
-
expect(result.diagnostics).to.have.length(
|
|
215
|
-
|
|
216
|
-
expect(
|
|
1307
|
+
expect(result.ok).to.be.true;
|
|
1308
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1309
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1310
|
+
expect(body).to.have.length(2);
|
|
1311
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1312
|
+
expect(body[1]?.kind).to.equal("ifStatement");
|
|
217
1313
|
});
|
|
218
|
-
|
|
219
|
-
describe("Destructuring Patterns", () => {
|
|
220
|
-
it("should transform array destructuring with yield", () => {
|
|
1314
|
+
it("should transform nested yield in while condition", () => {
|
|
221
1315
|
const module = createGeneratorModule([
|
|
222
1316
|
{
|
|
223
|
-
kind: "
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
{
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
elements: [
|
|
232
|
-
{ pattern: { kind: "identifierPattern", name: "a" } },
|
|
233
|
-
{ pattern: { kind: "identifierPattern", name: "b" } },
|
|
234
|
-
],
|
|
235
|
-
},
|
|
236
|
-
initializer: createYield({ kind: "literal", value: null }),
|
|
237
|
-
},
|
|
238
|
-
],
|
|
1317
|
+
kind: "whileStatement",
|
|
1318
|
+
condition: {
|
|
1319
|
+
kind: "logical",
|
|
1320
|
+
operator: "&&",
|
|
1321
|
+
left: createYield({ kind: "literal", value: true }),
|
|
1322
|
+
right: { kind: "literal", value: true },
|
|
1323
|
+
},
|
|
1324
|
+
body: { kind: "blockStatement", statements: [] },
|
|
239
1325
|
},
|
|
240
1326
|
]);
|
|
241
1327
|
const result = runYieldLoweringPass([module]);
|
|
242
1328
|
expect(result.ok).to.be.true;
|
|
1329
|
+
expect(result.diagnostics).to.have.length(0);
|
|
243
1330
|
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
244
|
-
|
|
245
|
-
expect(
|
|
1331
|
+
expect(body).to.have.length(1);
|
|
1332
|
+
expect(body[0]?.kind).to.equal("whileStatement");
|
|
246
1333
|
});
|
|
247
|
-
it("should transform
|
|
1334
|
+
it("should transform nested yield in for-of expression", () => {
|
|
248
1335
|
const module = createGeneratorModule([
|
|
249
1336
|
{
|
|
250
|
-
kind: "
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
kind: "property",
|
|
261
|
-
key: "x",
|
|
262
|
-
value: { kind: "identifierPattern", name: "x" },
|
|
263
|
-
shorthand: true,
|
|
264
|
-
},
|
|
265
|
-
],
|
|
266
|
-
},
|
|
267
|
-
initializer: createYield({ kind: "literal", value: null }),
|
|
268
|
-
},
|
|
269
|
-
],
|
|
1337
|
+
kind: "forOfStatement",
|
|
1338
|
+
variable: { kind: "identifierPattern", name: "x" },
|
|
1339
|
+
expression: {
|
|
1340
|
+
kind: "binary",
|
|
1341
|
+
operator: "+",
|
|
1342
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1343
|
+
right: { kind: "literal", value: 2 },
|
|
1344
|
+
},
|
|
1345
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1346
|
+
isAwait: false,
|
|
270
1347
|
},
|
|
271
1348
|
]);
|
|
272
1349
|
const result = runYieldLoweringPass([module]);
|
|
273
1350
|
expect(result.ok).to.be.true;
|
|
1351
|
+
expect(result.diagnostics).to.have.length(0);
|
|
274
1352
|
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
275
|
-
|
|
276
|
-
expect(
|
|
1353
|
+
expect(body).to.have.length(2);
|
|
1354
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1355
|
+
expect(body[1]?.kind).to.equal("forOfStatement");
|
|
277
1356
|
});
|
|
278
|
-
|
|
279
|
-
describe("Unsupported Patterns (TSN6101)", () => {
|
|
280
|
-
it("should reject yield in call argument", () => {
|
|
1357
|
+
it("should transform nested yield in for-in expression", () => {
|
|
281
1358
|
const module = createGeneratorModule([
|
|
282
1359
|
{
|
|
283
|
-
kind: "
|
|
1360
|
+
kind: "forInStatement",
|
|
1361
|
+
variable: { kind: "identifierPattern", name: "k" },
|
|
284
1362
|
expression: {
|
|
285
|
-
kind: "
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
1363
|
+
kind: "binary",
|
|
1364
|
+
operator: "+",
|
|
1365
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1366
|
+
right: { kind: "literal", value: 2 },
|
|
289
1367
|
},
|
|
1368
|
+
body: { kind: "blockStatement", statements: [] },
|
|
290
1369
|
},
|
|
291
1370
|
]);
|
|
292
1371
|
const result = runYieldLoweringPass([module]);
|
|
293
|
-
expect(result.ok).to.be.
|
|
294
|
-
expect(result.diagnostics
|
|
1372
|
+
expect(result.ok).to.be.true;
|
|
1373
|
+
expect(result.diagnostics).to.have.length(0);
|
|
1374
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1375
|
+
expect(body).to.have.length(2);
|
|
1376
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1377
|
+
expect(body[1]?.kind).to.equal("forInStatement");
|
|
295
1378
|
});
|
|
296
|
-
|
|
1379
|
+
});
|
|
1380
|
+
describe("Control Flow Structures", () => {
|
|
1381
|
+
it("should transform direct yield in if condition", () => {
|
|
297
1382
|
const module = createGeneratorModule([
|
|
298
1383
|
{
|
|
299
|
-
kind: "
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
initializer: {
|
|
308
|
-
kind: "binary",
|
|
309
|
-
operator: "+",
|
|
310
|
-
left: createYield({ kind: "literal", value: 1 }),
|
|
311
|
-
right: { kind: "literal", value: 2 },
|
|
1384
|
+
kind: "ifStatement",
|
|
1385
|
+
condition: createYield({ kind: "literal", value: true }),
|
|
1386
|
+
thenStatement: {
|
|
1387
|
+
kind: "blockStatement",
|
|
1388
|
+
statements: [
|
|
1389
|
+
{
|
|
1390
|
+
kind: "expressionStatement",
|
|
1391
|
+
expression: { kind: "literal", value: 1 },
|
|
312
1392
|
},
|
|
313
|
-
|
|
314
|
-
|
|
1393
|
+
],
|
|
1394
|
+
},
|
|
315
1395
|
},
|
|
316
1396
|
]);
|
|
317
1397
|
const result = runYieldLoweringPass([module]);
|
|
318
|
-
expect(result.ok).to.be.
|
|
319
|
-
|
|
1398
|
+
expect(result.ok).to.be.true;
|
|
1399
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1400
|
+
expect(body).to.have.length(2);
|
|
1401
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1402
|
+
expect(body[1]?.kind).to.equal("ifStatement");
|
|
320
1403
|
});
|
|
321
|
-
it("should
|
|
1404
|
+
it("should transform yield inside if statement", () => {
|
|
322
1405
|
const module = createGeneratorModule([
|
|
323
1406
|
{
|
|
324
|
-
kind: "
|
|
325
|
-
|
|
1407
|
+
kind: "ifStatement",
|
|
1408
|
+
condition: { kind: "literal", value: true },
|
|
1409
|
+
thenStatement: {
|
|
1410
|
+
kind: "blockStatement",
|
|
1411
|
+
statements: [
|
|
1412
|
+
{
|
|
1413
|
+
kind: "expressionStatement",
|
|
1414
|
+
expression: createYield({ kind: "literal", value: 1 }),
|
|
1415
|
+
},
|
|
1416
|
+
],
|
|
1417
|
+
},
|
|
326
1418
|
},
|
|
327
1419
|
]);
|
|
328
1420
|
const result = runYieldLoweringPass([module]);
|
|
329
|
-
expect(result.ok).to.be.
|
|
330
|
-
|
|
1421
|
+
expect(result.ok).to.be.true;
|
|
1422
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1423
|
+
const ifStmt = body[0];
|
|
1424
|
+
const thenBlock = ifStmt.thenStatement;
|
|
1425
|
+
expect(thenBlock.statements[0]?.kind).to.equal("yieldStatement");
|
|
331
1426
|
});
|
|
332
|
-
it("should
|
|
1427
|
+
it("should transform yield inside while loop", () => {
|
|
333
1428
|
const module = createGeneratorModule([
|
|
334
1429
|
{
|
|
335
|
-
kind: "
|
|
336
|
-
|
|
1430
|
+
kind: "whileStatement",
|
|
1431
|
+
condition: { kind: "literal", value: true },
|
|
1432
|
+
body: {
|
|
1433
|
+
kind: "blockStatement",
|
|
1434
|
+
statements: [
|
|
1435
|
+
{
|
|
1436
|
+
kind: "expressionStatement",
|
|
1437
|
+
expression: createYield({ kind: "identifier", name: "i" }),
|
|
1438
|
+
},
|
|
1439
|
+
],
|
|
1440
|
+
},
|
|
337
1441
|
},
|
|
338
1442
|
]);
|
|
339
1443
|
const result = runYieldLoweringPass([module]);
|
|
340
|
-
expect(result.ok).to.be.
|
|
341
|
-
expect(result.diagnostics[0]?.code).to.equal("TSN6101");
|
|
1444
|
+
expect(result.ok).to.be.true;
|
|
342
1445
|
});
|
|
343
|
-
it("should
|
|
1446
|
+
it("should transform direct yield in for loop condition", () => {
|
|
344
1447
|
const module = createGeneratorModule([
|
|
345
1448
|
{
|
|
346
1449
|
kind: "forStatement",
|
|
347
1450
|
condition: createYield({ kind: "literal", value: true }),
|
|
1451
|
+
update: {
|
|
1452
|
+
kind: "update",
|
|
1453
|
+
operator: "++",
|
|
1454
|
+
expression: { kind: "identifier", name: "i" },
|
|
1455
|
+
prefix: false,
|
|
1456
|
+
},
|
|
348
1457
|
body: { kind: "blockStatement", statements: [] },
|
|
349
1458
|
},
|
|
350
1459
|
]);
|
|
351
1460
|
const result = runYieldLoweringPass([module]);
|
|
352
|
-
expect(result.ok).to.be.
|
|
353
|
-
|
|
1461
|
+
expect(result.ok).to.be.true;
|
|
1462
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1463
|
+
expect(body).to.have.length(1);
|
|
1464
|
+
const forStmt = body[0];
|
|
1465
|
+
expect(forStmt.condition?.kind).to.equal("literal");
|
|
1466
|
+
expect(forStmt.body.kind).to.equal("blockStatement");
|
|
1467
|
+
const forBody = forStmt.body;
|
|
1468
|
+
expect(forBody.statements[0]?.kind).to.equal("yieldStatement");
|
|
1469
|
+
expect(forBody.statements[1]?.kind).to.equal("ifStatement");
|
|
354
1470
|
});
|
|
355
|
-
it("should
|
|
1471
|
+
it("should transform direct yield in for loop update", () => {
|
|
356
1472
|
const module = createGeneratorModule([
|
|
357
1473
|
{
|
|
358
1474
|
kind: "forStatement",
|
|
359
|
-
condition: {
|
|
1475
|
+
condition: {
|
|
1476
|
+
kind: "binary",
|
|
1477
|
+
operator: "<",
|
|
1478
|
+
left: { kind: "identifier", name: "i" },
|
|
1479
|
+
right: { kind: "literal", value: 3 },
|
|
1480
|
+
},
|
|
360
1481
|
update: createYield({ kind: "literal", value: 1 }),
|
|
361
1482
|
body: { kind: "blockStatement", statements: [] },
|
|
362
1483
|
},
|
|
363
1484
|
]);
|
|
364
1485
|
const result = runYieldLoweringPass([module]);
|
|
365
|
-
expect(result.ok).to.be.
|
|
366
|
-
|
|
1486
|
+
expect(result.ok).to.be.true;
|
|
1487
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1488
|
+
expect(body).to.have.length(2);
|
|
1489
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
1490
|
+
const forStmt = body[1];
|
|
1491
|
+
expect(forStmt.condition?.kind).to.equal("literal");
|
|
1492
|
+
expect(forStmt.update).to.equal(undefined);
|
|
1493
|
+
expect(forStmt.body.kind).to.equal("blockStatement");
|
|
1494
|
+
const forBody = forStmt.body;
|
|
1495
|
+
expect(forBody.statements[0]?.kind).to.equal("ifStatement");
|
|
1496
|
+
expect(forBody.statements[1]?.kind).to.equal("expressionStatement");
|
|
1497
|
+
expect(forBody.statements[2]?.kind).to.equal("ifStatement");
|
|
367
1498
|
});
|
|
368
|
-
|
|
369
|
-
describe("Control Flow Structures", () => {
|
|
370
|
-
it("should transform yield inside if statement", () => {
|
|
1499
|
+
it("should transform direct yield in both for loop condition and update", () => {
|
|
371
1500
|
const module = createGeneratorModule([
|
|
372
1501
|
{
|
|
373
|
-
kind: "
|
|
374
|
-
condition: { kind: "literal", value: true },
|
|
375
|
-
|
|
1502
|
+
kind: "forStatement",
|
|
1503
|
+
condition: createYield({ kind: "literal", value: true }),
|
|
1504
|
+
update: createYield({ kind: "literal", value: 1 }),
|
|
1505
|
+
body: {
|
|
376
1506
|
kind: "blockStatement",
|
|
377
|
-
statements: [
|
|
378
|
-
{
|
|
379
|
-
kind: "expressionStatement",
|
|
380
|
-
expression: createYield({ kind: "literal", value: 1 }),
|
|
381
|
-
},
|
|
382
|
-
],
|
|
1507
|
+
statements: [{ kind: "continueStatement" }],
|
|
383
1508
|
},
|
|
384
1509
|
},
|
|
385
1510
|
]);
|
|
386
1511
|
const result = runYieldLoweringPass([module]);
|
|
387
1512
|
expect(result.ok).to.be.true;
|
|
388
1513
|
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
1514
|
+
expect(body).to.have.length(2);
|
|
1515
|
+
expect(body[0]?.kind).to.equal("variableDeclaration");
|
|
1516
|
+
const forStmt = body[1];
|
|
1517
|
+
expect(forStmt.condition?.kind).to.equal("literal");
|
|
1518
|
+
expect(forStmt.update).to.equal(undefined);
|
|
1519
|
+
const forBody = forStmt.body;
|
|
1520
|
+
expect(forBody.statements[0]?.kind).to.equal("ifStatement");
|
|
1521
|
+
expect(forBody.statements[2]?.kind).to.equal("yieldStatement");
|
|
1522
|
+
expect(forBody.statements[3]?.kind).to.equal("ifStatement");
|
|
392
1523
|
});
|
|
393
|
-
it("should transform yield
|
|
1524
|
+
it("should transform direct yield in while condition", () => {
|
|
394
1525
|
const module = createGeneratorModule([
|
|
395
1526
|
{
|
|
396
1527
|
kind: "whileStatement",
|
|
397
|
-
condition: { kind: "literal", value: true },
|
|
1528
|
+
condition: createYield({ kind: "literal", value: true }),
|
|
398
1529
|
body: {
|
|
399
1530
|
kind: "blockStatement",
|
|
400
1531
|
statements: [
|
|
401
1532
|
{
|
|
402
1533
|
kind: "expressionStatement",
|
|
403
|
-
expression:
|
|
1534
|
+
expression: { kind: "literal", value: 1 },
|
|
404
1535
|
},
|
|
405
1536
|
],
|
|
406
1537
|
},
|
|
@@ -408,6 +1539,50 @@ describe("Yield Lowering Pass", () => {
|
|
|
408
1539
|
]);
|
|
409
1540
|
const result = runYieldLoweringPass([module]);
|
|
410
1541
|
expect(result.ok).to.be.true;
|
|
1542
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1543
|
+
expect(body).to.have.length(1);
|
|
1544
|
+
const whileStmt = body[0];
|
|
1545
|
+
expect(whileStmt.condition.kind).to.equal("literal");
|
|
1546
|
+
if (whileStmt.condition.kind === "literal") {
|
|
1547
|
+
expect(whileStmt.condition.value).to.equal(true);
|
|
1548
|
+
}
|
|
1549
|
+
expect(whileStmt.body.kind).to.equal("blockStatement");
|
|
1550
|
+
const whileBody = whileStmt.body;
|
|
1551
|
+
expect(whileBody.statements[0]?.kind).to.equal("yieldStatement");
|
|
1552
|
+
expect(whileBody.statements[1]?.kind).to.equal("ifStatement");
|
|
1553
|
+
});
|
|
1554
|
+
it("should transform direct yield in for-of expression", () => {
|
|
1555
|
+
const module = createGeneratorModule([
|
|
1556
|
+
{
|
|
1557
|
+
kind: "forOfStatement",
|
|
1558
|
+
variable: { kind: "identifierPattern", name: "x" },
|
|
1559
|
+
expression: createYield({ kind: "array", elements: [] }),
|
|
1560
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1561
|
+
isAwait: false,
|
|
1562
|
+
},
|
|
1563
|
+
]);
|
|
1564
|
+
const result = runYieldLoweringPass([module]);
|
|
1565
|
+
expect(result.ok).to.be.true;
|
|
1566
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1567
|
+
expect(body).to.have.length(2);
|
|
1568
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1569
|
+
expect(body[1]?.kind).to.equal("forOfStatement");
|
|
1570
|
+
});
|
|
1571
|
+
it("should transform direct yield in for-in expression", () => {
|
|
1572
|
+
const module = createGeneratorModule([
|
|
1573
|
+
{
|
|
1574
|
+
kind: "forInStatement",
|
|
1575
|
+
variable: { kind: "identifierPattern", name: "k" },
|
|
1576
|
+
expression: createYield({ kind: "object", properties: [] }),
|
|
1577
|
+
body: { kind: "blockStatement", statements: [] },
|
|
1578
|
+
},
|
|
1579
|
+
]);
|
|
1580
|
+
const result = runYieldLoweringPass([module]);
|
|
1581
|
+
expect(result.ok).to.be.true;
|
|
1582
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1583
|
+
expect(body).to.have.length(2);
|
|
1584
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1585
|
+
expect(body[1]?.kind).to.equal("forInStatement");
|
|
411
1586
|
});
|
|
412
1587
|
it("should transform yield inside switch case", () => {
|
|
413
1588
|
const module = createGeneratorModule([
|
|
@@ -431,6 +1606,27 @@ describe("Yield Lowering Pass", () => {
|
|
|
431
1606
|
const result = runYieldLoweringPass([module]);
|
|
432
1607
|
expect(result.ok).to.be.true;
|
|
433
1608
|
});
|
|
1609
|
+
it("should transform direct yield in switch expression", () => {
|
|
1610
|
+
const module = createGeneratorModule([
|
|
1611
|
+
{
|
|
1612
|
+
kind: "switchStatement",
|
|
1613
|
+
expression: createYield({ kind: "literal", value: 1 }),
|
|
1614
|
+
cases: [
|
|
1615
|
+
{
|
|
1616
|
+
kind: "switchCase",
|
|
1617
|
+
test: { kind: "literal", value: 1 },
|
|
1618
|
+
statements: [{ kind: "breakStatement" }],
|
|
1619
|
+
},
|
|
1620
|
+
],
|
|
1621
|
+
},
|
|
1622
|
+
]);
|
|
1623
|
+
const result = runYieldLoweringPass([module]);
|
|
1624
|
+
expect(result.ok).to.be.true;
|
|
1625
|
+
const body = getGeneratorBody(assertDefined(result.modules[0]));
|
|
1626
|
+
expect(body).to.have.length(2);
|
|
1627
|
+
expect(body[0]?.kind).to.equal("yieldStatement");
|
|
1628
|
+
expect(body[1]?.kind).to.equal("switchStatement");
|
|
1629
|
+
});
|
|
434
1630
|
it("should transform yield inside try block", () => {
|
|
435
1631
|
const module = createGeneratorModule([
|
|
436
1632
|
{
|
|
@@ -549,18 +1745,28 @@ describe("Yield Lowering Pass", () => {
|
|
|
549
1745
|
const module1 = createGeneratorModule([
|
|
550
1746
|
{
|
|
551
1747
|
kind: "returnStatement",
|
|
552
|
-
expression:
|
|
1748
|
+
expression: {
|
|
1749
|
+
kind: "binary",
|
|
1750
|
+
operator: "+",
|
|
1751
|
+
left: createYield({ kind: "literal", value: 1 }),
|
|
1752
|
+
right: { kind: "literal", value: 2 },
|
|
1753
|
+
},
|
|
553
1754
|
},
|
|
554
1755
|
]);
|
|
555
1756
|
const module2 = createGeneratorModule([
|
|
556
1757
|
{
|
|
557
1758
|
kind: "throwStatement",
|
|
558
|
-
expression:
|
|
1759
|
+
expression: {
|
|
1760
|
+
kind: "call",
|
|
1761
|
+
callee: { kind: "identifier", name: "wrap" },
|
|
1762
|
+
arguments: [createYield({ kind: "identifier", name: "err" })],
|
|
1763
|
+
isOptional: false,
|
|
1764
|
+
},
|
|
559
1765
|
},
|
|
560
1766
|
]);
|
|
561
1767
|
const result = runYieldLoweringPass([module1, module2]);
|
|
562
|
-
expect(result.ok).to.be.
|
|
563
|
-
expect(result.diagnostics).to.have.length(
|
|
1768
|
+
expect(result.ok).to.be.true;
|
|
1769
|
+
expect(result.diagnostics).to.have.length(0);
|
|
564
1770
|
});
|
|
565
1771
|
});
|
|
566
1772
|
describe("Pipeline Contract: No Yield Expressions After Lowering", () => {
|