@tsonic/emitter 0.0.62 → 0.0.64
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/adapter-generator.d.ts +5 -15
- package/dist/adapter-generator.d.ts.map +1 -1
- package/dist/adapter-generator.js +60 -53
- package/dist/adapter-generator.js.map +1 -1
- package/dist/contracts/backend-adapter.d.ts +36 -0
- package/dist/contracts/backend-adapter.d.ts.map +1 -0
- package/dist/contracts/backend-adapter.js +9 -0
- package/dist/contracts/backend-adapter.js.map +1 -0
- package/dist/contracts/emitter-contract.d.ts +54 -0
- package/dist/contracts/emitter-contract.d.ts.map +1 -0
- package/dist/contracts/emitter-contract.js +8 -0
- package/dist/contracts/emitter-contract.js.map +1 -0
- package/dist/contracts/import-classifier.d.ts +36 -0
- package/dist/contracts/import-classifier.d.ts.map +1 -0
- package/dist/contracts/import-classifier.js +9 -0
- package/dist/contracts/import-classifier.js.map +1 -0
- package/dist/core/{attributes.d.ts → format/attributes.d.ts} +9 -14
- package/dist/core/format/attributes.d.ts.map +1 -0
- package/dist/core/format/attributes.js +190 -0
- package/dist/core/format/attributes.js.map +1 -0
- package/dist/core/format/attributes.test.d.ts.map +1 -0
- package/dist/core/{attributes.test.js → format/attributes.test.js} +70 -32
- package/dist/core/format/attributes.test.js.map +1 -0
- package/dist/core/format/backend-ast/index.d.ts +7 -0
- package/dist/core/format/backend-ast/index.d.ts.map +1 -0
- package/dist/core/format/backend-ast/index.js +6 -0
- package/dist/core/format/backend-ast/index.js.map +1 -0
- package/dist/core/format/backend-ast/printer.d.ts +33 -0
- package/dist/core/format/backend-ast/printer.d.ts.map +1 -0
- package/dist/core/format/backend-ast/printer.js +1151 -0
- package/dist/core/format/backend-ast/printer.js.map +1 -0
- package/dist/core/format/backend-ast/types.d.ts +504 -0
- package/dist/core/format/backend-ast/types.d.ts.map +1 -0
- package/dist/core/format/backend-ast/types.js +13 -0
- package/dist/core/format/backend-ast/types.js.map +1 -0
- package/dist/core/format/backend-ast/utils.d.ts +26 -0
- package/dist/core/format/backend-ast/utils.d.ts.map +1 -0
- package/dist/core/format/backend-ast/utils.js +65 -0
- package/dist/core/format/backend-ast/utils.js.map +1 -0
- package/dist/core/{exports.d.ts → format/exports.d.ts} +2 -2
- package/dist/core/format/exports.d.ts.map +1 -0
- package/dist/core/format/exports.js +22 -0
- package/dist/core/format/exports.js.map +1 -0
- package/dist/core/format/index.d.ts +9 -0
- package/dist/core/format/index.d.ts.map +1 -0
- package/dist/core/format/index.js +9 -0
- package/dist/core/format/index.js.map +1 -0
- package/dist/core/{local-names.d.ts → format/local-names.d.ts} +1 -1
- package/dist/core/format/local-names.d.ts.map +1 -0
- package/dist/core/{local-names.js → format/local-names.js} +1 -1
- package/dist/core/format/local-names.js.map +1 -0
- package/dist/core/format/module-emitter/assembly.d.ts +27 -0
- package/dist/core/format/module-emitter/assembly.d.ts.map +1 -0
- package/dist/core/format/module-emitter/assembly.js +44 -0
- package/dist/core/format/module-emitter/assembly.js.map +1 -0
- package/dist/core/{module-emitter → format/module-emitter}/header.d.ts +1 -1
- package/dist/core/format/module-emitter/header.d.ts.map +1 -0
- package/dist/core/{module-emitter → format/module-emitter}/header.js +1 -1
- package/dist/core/format/module-emitter/header.js.map +1 -0
- package/dist/core/format/module-emitter/index.d.ts.map +1 -0
- package/dist/core/format/module-emitter/index.js.map +1 -0
- package/dist/core/format/module-emitter/namespace.d.ts +21 -0
- package/dist/core/format/module-emitter/namespace.d.ts.map +1 -0
- package/dist/core/format/module-emitter/namespace.js +58 -0
- package/dist/core/format/module-emitter/namespace.js.map +1 -0
- package/dist/core/{module-emitter → format/module-emitter}/orchestrator.d.ts +1 -1
- package/dist/core/format/module-emitter/orchestrator.d.ts.map +1 -0
- package/dist/core/{module-emitter → format/module-emitter}/orchestrator.js +19 -19
- package/dist/core/format/module-emitter/orchestrator.js.map +1 -0
- package/dist/core/format/module-emitter/separation.d.ts.map +1 -0
- package/dist/core/format/module-emitter/separation.js.map +1 -0
- package/dist/core/{module-emitter → format/module-emitter}/static-container.d.ts +8 -3
- package/dist/core/format/module-emitter/static-container.d.ts.map +1 -0
- package/dist/core/format/module-emitter/static-container.js +202 -0
- package/dist/core/format/module-emitter/static-container.js.map +1 -0
- package/dist/core/format/module-emitter.d.ts.map +1 -0
- package/dist/core/format/module-emitter.js.map +1 -0
- package/dist/core/{options.d.ts → format/options.d.ts} +1 -1
- package/dist/core/format/options.d.ts.map +1 -0
- package/dist/core/format/options.js.map +1 -0
- package/dist/core/index.d.ts +2 -7
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -7
- package/dist/core/index.js.map +1 -1
- package/dist/core/semantic/boolean-context.d.ts +44 -0
- package/dist/core/semantic/boolean-context.d.ts.map +1 -0
- package/dist/core/semantic/boolean-context.js +717 -0
- package/dist/core/semantic/boolean-context.js.map +1 -0
- package/dist/core/semantic/boolean-context.test.d.ts.map +1 -0
- package/dist/core/{boolean-context.test.js → semantic/boolean-context.test.js} +86 -109
- package/dist/core/semantic/boolean-context.test.js.map +1 -0
- package/dist/core/{imports.d.ts → semantic/imports.d.ts} +1 -5
- package/dist/core/semantic/imports.d.ts.map +1 -0
- package/dist/core/{imports.js → semantic/imports.js} +56 -74
- package/dist/core/semantic/imports.js.map +1 -0
- package/dist/core/semantic/imports.test.d.ts.map +1 -0
- package/dist/core/semantic/imports.test.js +229 -0
- package/dist/core/semantic/imports.test.js.map +1 -0
- package/dist/core/semantic/index.d.ts +15 -0
- package/dist/core/semantic/index.d.ts.map +1 -0
- package/dist/core/semantic/index.js +15 -0
- package/dist/core/semantic/index.js.map +1 -0
- package/dist/core/{local-types.d.ts → semantic/local-types.d.ts} +1 -1
- package/dist/core/semantic/local-types.d.ts.map +1 -0
- package/dist/core/semantic/local-types.js.map +1 -0
- package/dist/core/{module-map.d.ts → semantic/module-map.d.ts} +1 -1
- package/dist/core/semantic/module-map.d.ts.map +1 -0
- package/dist/core/semantic/module-map.js.map +1 -0
- package/dist/core/semantic/module-map.test.d.ts.map +1 -0
- package/dist/core/semantic/module-map.test.js.map +1 -0
- package/dist/core/semantic/naming-collisions.d.ts.map +1 -0
- package/dist/core/{naming-collisions.js → semantic/naming-collisions.js} +1 -1
- package/dist/core/semantic/naming-collisions.js.map +1 -0
- package/dist/core/{type-alias-index.d.ts → semantic/type-alias-index.d.ts} +1 -1
- package/dist/core/semantic/type-alias-index.d.ts.map +1 -0
- package/dist/core/semantic/type-alias-index.js.map +1 -0
- package/dist/core/semantic/type-compatibility.d.ts.map +1 -0
- package/dist/core/semantic/type-compatibility.js.map +1 -0
- package/dist/core/{type-member-index.d.ts → semantic/type-member-index.d.ts} +1 -1
- package/dist/core/semantic/type-member-index.d.ts.map +1 -0
- package/dist/core/semantic/type-member-index.js.map +1 -0
- package/dist/core/semantic/type-params.d.ts.map +1 -0
- package/dist/core/semantic/type-params.js.map +1 -0
- package/dist/core/{type-resolution.d.ts → semantic/type-resolution.d.ts} +3 -6
- package/dist/core/semantic/type-resolution.d.ts.map +1 -0
- package/dist/core/{type-resolution.js → semantic/type-resolution.js} +15 -25
- package/dist/core/semantic/type-resolution.js.map +1 -0
- package/dist/core/semantic/type-resolution.test.d.ts.map +1 -0
- package/dist/core/{type-resolution.test.js → semantic/type-resolution.test.js} +11 -19
- package/dist/core/semantic/type-resolution.test.js.map +1 -0
- package/dist/core/semantic/unsafe.d.ts.map +1 -0
- package/dist/core/semantic/unsafe.js.map +1 -0
- package/dist/emitter-types/core.d.ts +6 -12
- package/dist/emitter-types/core.d.ts.map +1 -1
- package/dist/emitter-types/index.d.ts +1 -1
- package/dist/emitter-types/index.d.ts.map +1 -1
- package/dist/emitter-types/index.js.map +1 -1
- package/dist/emitter.d.ts +1 -1
- package/dist/emitter.d.ts.map +1 -1
- package/dist/emitter.js +9 -8
- package/dist/emitter.js.map +1 -1
- package/dist/expression-emitter.d.ts +10 -5
- package/dist/expression-emitter.d.ts.map +1 -1
- package/dist/expression-emitter.js +333 -117
- package/dist/expression-emitter.js.map +1 -1
- package/dist/expressions/access.d.ts +4 -3
- package/dist/expressions/access.d.ts.map +1 -1
- package/dist/expressions/access.js +252 -102
- package/dist/expressions/access.js.map +1 -1
- package/dist/expressions/calls/call-analysis.d.ts +86 -0
- package/dist/expressions/calls/call-analysis.d.ts.map +1 -0
- package/dist/expressions/calls/call-analysis.js +284 -0
- package/dist/expressions/calls/call-analysis.js.map +1 -0
- package/dist/expressions/calls/call-emitter.d.ts +13 -0
- package/dist/expressions/calls/call-emitter.d.ts.map +1 -0
- package/dist/expressions/calls/call-emitter.js +1048 -0
- package/dist/expressions/calls/call-emitter.js.map +1 -0
- package/dist/expressions/calls/new-emitter.d.ts +13 -0
- package/dist/expressions/calls/new-emitter.d.ts.map +1 -0
- package/dist/expressions/calls/new-emitter.js +641 -0
- package/dist/expressions/calls/new-emitter.js.map +1 -0
- package/dist/expressions/calls.d.ts +2 -14
- package/dist/expressions/calls.d.ts.map +1 -1
- package/dist/expressions/calls.js +2 -909
- package/dist/expressions/calls.js.map +1 -1
- package/dist/expressions/collections.d.ts +6 -16
- package/dist/expressions/collections.d.ts.map +1 -1
- package/dist/expressions/collections.js +318 -217
- package/dist/expressions/collections.js.map +1 -1
- package/dist/expressions/functions.d.ts +6 -5
- package/dist/expressions/functions.d.ts.map +1 -1
- package/dist/expressions/functions.js +57 -62
- package/dist/expressions/functions.js.map +1 -1
- package/dist/expressions/identifiers.d.ts +11 -6
- package/dist/expressions/identifiers.d.ts.map +1 -1
- package/dist/expressions/identifiers.js +76 -25
- package/dist/expressions/identifiers.js.map +1 -1
- package/dist/expressions/index.d.ts +1 -1
- package/dist/expressions/index.d.ts.map +1 -1
- package/dist/expressions/index.js +1 -1
- package/dist/expressions/index.js.map +1 -1
- package/dist/expressions/index.test.js +605 -0
- package/dist/expressions/index.test.js.map +1 -1
- package/dist/expressions/literals.d.ts +4 -3
- package/dist/expressions/literals.d.ts.map +1 -1
- package/dist/expressions/literals.js +25 -17
- package/dist/expressions/literals.js.map +1 -1
- package/dist/expressions/literals.test.js +18 -18
- package/dist/expressions/literals.test.js.map +1 -1
- package/dist/expressions/operators/assignment-emitter.d.ts +16 -0
- package/dist/expressions/operators/assignment-emitter.d.ts.map +1 -0
- package/dist/expressions/operators/assignment-emitter.js +118 -0
- package/dist/expressions/operators/assignment-emitter.js.map +1 -0
- package/dist/expressions/operators/binary-emitter.d.ts +33 -0
- package/dist/expressions/operators/binary-emitter.d.ts.map +1 -0
- package/dist/expressions/operators/binary-emitter.js +398 -0
- package/dist/expressions/operators/binary-emitter.js.map +1 -0
- package/dist/expressions/operators/conditional-emitter.d.ts +17 -0
- package/dist/expressions/operators/conditional-emitter.d.ts.map +1 -0
- package/dist/expressions/operators/conditional-emitter.js +306 -0
- package/dist/expressions/operators/conditional-emitter.js.map +1 -0
- package/dist/expressions/operators/helpers.d.ts +37 -0
- package/dist/expressions/operators/helpers.d.ts.map +1 -0
- package/dist/expressions/operators/helpers.js +136 -0
- package/dist/expressions/operators/helpers.js.map +1 -0
- package/dist/expressions/operators/logical-emitter.d.ts +23 -0
- package/dist/expressions/operators/logical-emitter.d.ts.map +1 -0
- package/dist/expressions/operators/logical-emitter.js +73 -0
- package/dist/expressions/operators/logical-emitter.js.map +1 -0
- package/dist/expressions/operators/unary-emitter.d.ts +30 -0
- package/dist/expressions/operators/unary-emitter.d.ts.map +1 -0
- package/dist/expressions/operators/unary-emitter.js +244 -0
- package/dist/expressions/operators/unary-emitter.js.map +1 -0
- package/dist/expressions/operators.d.ts +5 -81
- package/dist/expressions/operators.d.ts.map +1 -1
- package/dist/expressions/operators.js +5 -949
- package/dist/expressions/operators.js.map +1 -1
- package/dist/expressions/other.d.ts +15 -11
- package/dist/expressions/other.d.ts.map +1 -1
- package/dist/expressions/other.js +51 -36
- package/dist/expressions/other.js.map +1 -1
- package/dist/expressions/precedence.test.js +1 -1
- package/dist/expressions/precedence.test.js.map +1 -1
- package/dist/generator-exchange.d.ts +10 -3
- package/dist/generator-exchange.d.ts.map +1 -1
- package/dist/generator-exchange.js +57 -54
- package/dist/generator-exchange.js.map +1 -1
- package/dist/generator-wrapper.d.ts +17 -65
- package/dist/generator-wrapper.d.ts.map +1 -1
- package/dist/generator-wrapper.js +396 -220
- package/dist/generator-wrapper.js.map +1 -1
- package/dist/generator-wrapper.test.js +22 -14
- package/dist/generator-wrapper.test.js.map +1 -1
- package/dist/integration.test.js +169 -1
- package/dist/integration.test.js.map +1 -1
- package/dist/patterns.d.ts +18 -88
- package/dist/patterns.d.ts.map +1 -1
- package/dist/patterns.js +540 -304
- package/dist/patterns.js.map +1 -1
- package/dist/patterns.test.js +5 -4
- package/dist/patterns.test.js.map +1 -1
- package/dist/specialization/generation.d.ts +7 -3
- package/dist/specialization/generation.d.ts.map +1 -1
- package/dist/specialization/generation.js +31 -15
- package/dist/specialization/generation.js.map +1 -1
- package/dist/specialization/type-aliases.test.js +47 -2
- package/dist/specialization/type-aliases.test.js.map +1 -1
- package/dist/statement-emitter.d.ts +15 -4
- package/dist/statement-emitter.d.ts.map +1 -1
- package/dist/statement-emitter.js +54 -47
- package/dist/statement-emitter.js.map +1 -1
- package/dist/statements/blocks.d.ts +24 -16
- package/dist/statements/blocks.d.ts.map +1 -1
- package/dist/statements/blocks.js +242 -65
- package/dist/statements/blocks.js.map +1 -1
- package/dist/statements/classes/index.d.ts +1 -1
- package/dist/statements/classes/index.d.ts.map +1 -1
- package/dist/statements/classes/index.js +1 -1
- package/dist/statements/classes/index.js.map +1 -1
- package/dist/statements/classes/inline-types.d.ts +4 -3
- package/dist/statements/classes/inline-types.d.ts.map +1 -1
- package/dist/statements/classes/inline-types.js +21 -21
- package/dist/statements/classes/inline-types.js.map +1 -1
- package/dist/statements/classes/members/constructors.d.ts +4 -3
- package/dist/statements/classes/members/constructors.d.ts.map +1 -1
- package/dist/statements/classes/members/constructors.js +57 -58
- package/dist/statements/classes/members/constructors.js.map +1 -1
- package/dist/statements/classes/members/methods.d.ts +4 -3
- package/dist/statements/classes/members/methods.d.ts.map +1 -1
- package/dist/statements/classes/members/methods.js +106 -101
- package/dist/statements/classes/members/methods.js.map +1 -1
- package/dist/statements/classes/members/orchestrator.d.ts +4 -3
- package/dist/statements/classes/members/orchestrator.d.ts.map +1 -1
- package/dist/statements/classes/members/orchestrator.js +2 -2
- package/dist/statements/classes/members/orchestrator.js.map +1 -1
- package/dist/statements/classes/members/properties.d.ts +4 -3
- package/dist/statements/classes/members/properties.d.ts.map +1 -1
- package/dist/statements/classes/members/properties.js +105 -88
- package/dist/statements/classes/members/properties.js.map +1 -1
- package/dist/statements/classes/members/shadowing.test.js +7 -2
- package/dist/statements/classes/members/shadowing.test.js.map +1 -1
- package/dist/statements/classes/members/static-readonly-properties.test.js +4 -1
- package/dist/statements/classes/members/static-readonly-properties.test.js.map +1 -1
- package/dist/statements/classes/parameters.d.ts +8 -10
- package/dist/statements/classes/parameters.d.ts.map +1 -1
- package/dist/statements/classes/parameters.js +30 -26
- package/dist/statements/classes/parameters.js.map +1 -1
- package/dist/statements/classes/properties.d.ts +4 -3
- package/dist/statements/classes/properties.d.ts.map +1 -1
- package/dist/statements/classes/properties.js +76 -50
- package/dist/statements/classes/properties.js.map +1 -1
- package/dist/statements/classes.d.ts +1 -1
- package/dist/statements/classes.d.ts.map +1 -1
- package/dist/statements/classes.js +1 -1
- package/dist/statements/classes.js.map +1 -1
- package/dist/statements/control/conditionals/guard-analysis.d.ts +169 -0
- package/dist/statements/control/conditionals/guard-analysis.d.ts.map +1 -0
- package/dist/statements/control/conditionals/guard-analysis.js +591 -0
- package/dist/statements/control/conditionals/guard-analysis.js.map +1 -0
- package/dist/statements/control/conditionals/if-emitter.d.ts +14 -0
- package/dist/statements/control/conditionals/if-emitter.d.ts.map +1 -0
- package/dist/statements/control/conditionals/if-emitter.js +725 -0
- package/dist/statements/control/conditionals/if-emitter.js.map +1 -0
- package/dist/statements/control/conditionals/switch-emitter.d.ts +13 -0
- package/dist/statements/control/conditionals/switch-emitter.d.ts.map +1 -0
- package/dist/statements/control/conditionals/switch-emitter.js +60 -0
- package/dist/statements/control/conditionals/switch-emitter.js.map +1 -0
- package/dist/statements/control/conditionals.d.ts +3 -15
- package/dist/statements/control/conditionals.d.ts.map +1 -1
- package/dist/statements/control/conditionals.js +3 -1152
- package/dist/statements/control/conditionals.js.map +1 -1
- package/dist/statements/control/exceptions.d.ts +8 -6
- package/dist/statements/control/exceptions.d.ts.map +1 -1
- package/dist/statements/control/exceptions.js +35 -23
- package/dist/statements/control/exceptions.js.map +1 -1
- package/dist/statements/control/index.d.ts +3 -3
- package/dist/statements/control/index.d.ts.map +1 -1
- package/dist/statements/control/index.js +3 -3
- package/dist/statements/control/index.js.map +1 -1
- package/dist/statements/control/loops.d.ts +14 -12
- package/dist/statements/control/loops.d.ts.map +1 -1
- package/dist/statements/control/loops.js +147 -82
- package/dist/statements/control/loops.js.map +1 -1
- package/dist/statements/control.d.ts +1 -1
- package/dist/statements/control.d.ts.map +1 -1
- package/dist/statements/control.js +1 -1
- package/dist/statements/control.js.map +1 -1
- package/dist/statements/declarations/classes.d.ts +7 -3
- package/dist/statements/declarations/classes.d.ts.map +1 -1
- package/dist/statements/declarations/classes.js +107 -83
- package/dist/statements/declarations/classes.js.map +1 -1
- package/dist/statements/declarations/enums.d.ts +4 -3
- package/dist/statements/declarations/enums.d.ts.map +1 -1
- package/dist/statements/declarations/enums.js +16 -15
- package/dist/statements/declarations/enums.js.map +1 -1
- package/dist/statements/declarations/functions.d.ts +18 -2
- package/dist/statements/declarations/functions.d.ts.map +1 -1
- package/dist/statements/declarations/functions.js +633 -162
- package/dist/statements/declarations/functions.js.map +1 -1
- package/dist/statements/declarations/index.d.ts +2 -2
- package/dist/statements/declarations/index.d.ts.map +1 -1
- package/dist/statements/declarations/index.js +2 -2
- package/dist/statements/declarations/index.js.map +1 -1
- package/dist/statements/declarations/interfaces.d.ts +7 -3
- package/dist/statements/declarations/interfaces.d.ts.map +1 -1
- package/dist/statements/declarations/interfaces.js +138 -105
- package/dist/statements/declarations/interfaces.js.map +1 -1
- package/dist/statements/declarations/type-aliases.d.ts +7 -3
- package/dist/statements/declarations/type-aliases.d.ts.map +1 -1
- package/dist/statements/declarations/type-aliases.js +122 -82
- package/dist/statements/declarations/type-aliases.js.map +1 -1
- package/dist/statements/declarations/variables.d.ts +12 -2
- package/dist/statements/declarations/variables.d.ts.map +1 -1
- package/dist/statements/declarations/variables.js +541 -428
- package/dist/statements/declarations/variables.js.map +1 -1
- package/dist/statements/declarations.d.ts +1 -1
- package/dist/statements/declarations.d.ts.map +1 -1
- package/dist/statements/declarations.js +1 -1
- package/dist/statements/declarations.js.map +1 -1
- package/dist/statements/index.d.ts +3 -3
- package/dist/statements/index.d.ts.map +1 -1
- package/dist/statements/index.js +5 -5
- package/dist/statements/index.js.map +1 -1
- package/dist/statements/index.test.js +307 -0
- package/dist/statements/index.test.js.map +1 -1
- package/dist/type-emitter.d.ts +1 -1
- package/dist/type-emitter.d.ts.map +1 -1
- package/dist/type-emitter.js +1 -1
- package/dist/type-emitter.js.map +1 -1
- package/dist/types/arrays.d.ts +3 -2
- package/dist/types/arrays.d.ts.map +1 -1
- package/dist/types/arrays.js +7 -5
- package/dist/types/arrays.js.map +1 -1
- package/dist/types/dictionaries.d.ts +6 -3
- package/dist/types/dictionaries.d.ts.map +1 -1
- package/dist/types/dictionaries.js +22 -10
- package/dist/types/dictionaries.js.map +1 -1
- package/dist/types/emitter.d.ts +8 -2
- package/dist/types/emitter.d.ts.map +1 -1
- package/dist/types/emitter.js +20 -6
- package/dist/types/emitter.js.map +1 -1
- package/dist/types/functions.d.ts +3 -2
- package/dist/types/functions.d.ts.map +1 -1
- package/dist/types/functions.js +36 -13
- package/dist/types/functions.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.test.js +137 -0
- package/dist/types/index.test.js.map +1 -1
- package/dist/types/intersections.d.ts +3 -2
- package/dist/types/intersections.d.ts.map +1 -1
- package/dist/types/intersections.js +2 -2
- package/dist/types/intersections.js.map +1 -1
- package/dist/types/literals.d.ts +9 -2
- package/dist/types/literals.d.ts.map +1 -1
- package/dist/types/literals.js +11 -5
- package/dist/types/literals.js.map +1 -1
- package/dist/types/objects.d.ts +3 -2
- package/dist/types/objects.d.ts.map +1 -1
- package/dist/types/objects.js +1 -1
- package/dist/types/objects.js.map +1 -1
- package/dist/types/parameters.d.ts +6 -5
- package/dist/types/parameters.d.ts.map +1 -1
- package/dist/types/parameters.js +88 -29
- package/dist/types/parameters.js.map +1 -1
- package/dist/types/parameters.test.js +9 -4
- package/dist/types/parameters.test.js.map +1 -1
- package/dist/types/primitives.d.ts +5 -4
- package/dist/types/primitives.d.ts.map +1 -1
- package/dist/types/primitives.js +14 -13
- package/dist/types/primitives.js.map +1 -1
- package/dist/types/references.d.ts +3 -2
- package/dist/types/references.d.ts.map +1 -1
- package/dist/types/references.js +135 -111
- package/dist/types/references.js.map +1 -1
- package/dist/types/tuples.d.ts +3 -2
- package/dist/types/tuples.d.ts.map +1 -1
- package/dist/types/tuples.js +25 -11
- package/dist/types/tuples.js.map +1 -1
- package/dist/types/unions.d.ts +3 -2
- package/dist/types/unions.d.ts.map +1 -1
- package/dist/types/unions.js +36 -21
- package/dist/types/unions.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
- package/dist/core/attributes.d.ts.map +0 -1
- package/dist/core/attributes.js +0 -141
- package/dist/core/attributes.js.map +0 -1
- package/dist/core/attributes.test.d.ts.map +0 -1
- package/dist/core/attributes.test.js.map +0 -1
- package/dist/core/boolean-context.d.ts +0 -42
- package/dist/core/boolean-context.d.ts.map +0 -1
- package/dist/core/boolean-context.js +0 -442
- package/dist/core/boolean-context.js.map +0 -1
- package/dist/core/boolean-context.test.d.ts.map +0 -1
- package/dist/core/boolean-context.test.js.map +0 -1
- package/dist/core/exports.d.ts.map +0 -1
- package/dist/core/exports.js +0 -28
- package/dist/core/exports.js.map +0 -1
- package/dist/core/imports.d.ts.map +0 -1
- package/dist/core/imports.js.map +0 -1
- package/dist/core/imports.test.d.ts.map +0 -1
- package/dist/core/imports.test.js +0 -79
- package/dist/core/imports.test.js.map +0 -1
- package/dist/core/local-names.d.ts.map +0 -1
- package/dist/core/local-names.js.map +0 -1
- package/dist/core/local-types.d.ts.map +0 -1
- package/dist/core/local-types.js.map +0 -1
- package/dist/core/module-emitter/assembly.d.ts +0 -24
- package/dist/core/module-emitter/assembly.d.ts.map +0 -1
- package/dist/core/module-emitter/assembly.js +0 -69
- package/dist/core/module-emitter/assembly.js.map +0 -1
- package/dist/core/module-emitter/header.d.ts.map +0 -1
- package/dist/core/module-emitter/header.js.map +0 -1
- package/dist/core/module-emitter/index.d.ts.map +0 -1
- package/dist/core/module-emitter/index.js.map +0 -1
- package/dist/core/module-emitter/namespace.d.ts +0 -14
- package/dist/core/module-emitter/namespace.d.ts.map +0 -1
- package/dist/core/module-emitter/namespace.js +0 -26
- package/dist/core/module-emitter/namespace.js.map +0 -1
- package/dist/core/module-emitter/orchestrator.d.ts.map +0 -1
- package/dist/core/module-emitter/orchestrator.js.map +0 -1
- package/dist/core/module-emitter/separation.d.ts.map +0 -1
- package/dist/core/module-emitter/separation.js.map +0 -1
- package/dist/core/module-emitter/static-container.d.ts.map +0 -1
- package/dist/core/module-emitter/static-container.js +0 -139
- package/dist/core/module-emitter/static-container.js.map +0 -1
- package/dist/core/module-emitter.d.ts.map +0 -1
- package/dist/core/module-emitter.js.map +0 -1
- package/dist/core/module-map.d.ts.map +0 -1
- package/dist/core/module-map.js.map +0 -1
- package/dist/core/module-map.test.d.ts.map +0 -1
- package/dist/core/module-map.test.js.map +0 -1
- package/dist/core/naming-collisions.d.ts.map +0 -1
- package/dist/core/naming-collisions.js.map +0 -1
- package/dist/core/options.d.ts.map +0 -1
- package/dist/core/options.js.map +0 -1
- package/dist/core/type-alias-index.d.ts.map +0 -1
- package/dist/core/type-alias-index.js.map +0 -1
- package/dist/core/type-compatibility.d.ts.map +0 -1
- package/dist/core/type-compatibility.js.map +0 -1
- package/dist/core/type-member-index.d.ts.map +0 -1
- package/dist/core/type-member-index.js.map +0 -1
- package/dist/core/type-params.d.ts.map +0 -1
- package/dist/core/type-params.js.map +0 -1
- package/dist/core/type-resolution.d.ts.map +0 -1
- package/dist/core/type-resolution.js.map +0 -1
- package/dist/core/type-resolution.test.d.ts.map +0 -1
- package/dist/core/type-resolution.test.js.map +0 -1
- package/dist/core/unsafe.d.ts.map +0 -1
- package/dist/core/unsafe.js.map +0 -1
- /package/dist/core/{attributes.test.d.ts → format/attributes.test.d.ts} +0 -0
- /package/dist/core/{module-emitter → format/module-emitter}/index.d.ts +0 -0
- /package/dist/core/{module-emitter → format/module-emitter}/index.js +0 -0
- /package/dist/core/{module-emitter → format/module-emitter}/separation.d.ts +0 -0
- /package/dist/core/{module-emitter → format/module-emitter}/separation.js +0 -0
- /package/dist/core/{module-emitter.d.ts → format/module-emitter.d.ts} +0 -0
- /package/dist/core/{module-emitter.js → format/module-emitter.js} +0 -0
- /package/dist/core/{options.js → format/options.js} +0 -0
- /package/dist/core/{boolean-context.test.d.ts → semantic/boolean-context.test.d.ts} +0 -0
- /package/dist/core/{imports.test.d.ts → semantic/imports.test.d.ts} +0 -0
- /package/dist/core/{local-types.js → semantic/local-types.js} +0 -0
- /package/dist/core/{module-map.js → semantic/module-map.js} +0 -0
- /package/dist/core/{module-map.test.d.ts → semantic/module-map.test.d.ts} +0 -0
- /package/dist/core/{module-map.test.js → semantic/module-map.test.js} +0 -0
- /package/dist/core/{naming-collisions.d.ts → semantic/naming-collisions.d.ts} +0 -0
- /package/dist/core/{type-alias-index.js → semantic/type-alias-index.js} +0 -0
- /package/dist/core/{type-compatibility.d.ts → semantic/type-compatibility.d.ts} +0 -0
- /package/dist/core/{type-compatibility.js → semantic/type-compatibility.js} +0 -0
- /package/dist/core/{type-member-index.js → semantic/type-member-index.js} +0 -0
- /package/dist/core/{type-params.d.ts → semantic/type-params.d.ts} +0 -0
- /package/dist/core/{type-params.js → semantic/type-params.js} +0 -0
- /package/dist/core/{type-resolution.test.d.ts → semantic/type-resolution.test.d.ts} +0 -0
- /package/dist/core/{unsafe.d.ts → semantic/unsafe.d.ts} +0 -0
- /package/dist/core/{unsafe.js → semantic/unsafe.js} +0 -0
|
@@ -0,0 +1,725 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* If-statement emitter with union/instanceof/nullable guard narrowing.
|
|
3
|
+
* Returns CSharpStatementAst nodes.
|
|
4
|
+
*/
|
|
5
|
+
import { emitExpressionAst } from "../../../expression-emitter.js";
|
|
6
|
+
import { emitIdentifier } from "../../../expressions/identifiers.js";
|
|
7
|
+
import { emitStatementAst } from "../../../statement-emitter.js";
|
|
8
|
+
import { escapeCSharpIdentifier } from "../../../emitter-types/index.js";
|
|
9
|
+
import { emitBooleanConditionAst, toBooleanConditionAst, } from "../../../core/semantic/boolean-context.js";
|
|
10
|
+
import { tryResolvePredicateGuard, tryResolveInstanceofGuard, tryResolveInGuard, tryResolveDiscriminantEqualityGuard, tryResolveSimpleNullableGuard, tryResolveNullableGuard, isDefinitelyTerminating, } from "./guard-analysis.js";
|
|
11
|
+
/** Standard emitExpressionAst adapter for emitBooleanConditionAst callback. */
|
|
12
|
+
const emitExprAstCb = (e, ctx) => emitExpressionAst(e, ctx);
|
|
13
|
+
/**
|
|
14
|
+
* Build AST for a union narrowing expression: (escapedOrig.AsN())
|
|
15
|
+
*/
|
|
16
|
+
const buildUnionNarrowAst = (escapedOrig, memberN) => ({
|
|
17
|
+
kind: "parenthesizedExpression",
|
|
18
|
+
expression: {
|
|
19
|
+
kind: "invocationExpression",
|
|
20
|
+
expression: {
|
|
21
|
+
kind: "memberAccessExpression",
|
|
22
|
+
expression: { kind: "identifierExpression", identifier: escapedOrig },
|
|
23
|
+
memberName: `As${memberN}`,
|
|
24
|
+
},
|
|
25
|
+
arguments: [],
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
/** Wrap an array of statements in a single statement (block if >1). */
|
|
29
|
+
const wrapInBlock = (stmts) => {
|
|
30
|
+
if (stmts.length === 1 && stmts[0])
|
|
31
|
+
return stmts[0];
|
|
32
|
+
return { kind: "blockStatement", statements: [...stmts] };
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Emit a forced block with a preamble line as AST.
|
|
36
|
+
* Builds a blockStatement with preamble statements + body statements.
|
|
37
|
+
*
|
|
38
|
+
* If bodyStmt is already a block, its statements are inlined to avoid nesting.
|
|
39
|
+
*/
|
|
40
|
+
const emitForcedBlockWithPreambleAst = (preambleStmts, bodyStmt, bodyCtx) => {
|
|
41
|
+
const allStatements = [...preambleStmts];
|
|
42
|
+
const emitBodyStatements = (statements, ctx) => {
|
|
43
|
+
let currentCtx = ctx;
|
|
44
|
+
for (const s of statements) {
|
|
45
|
+
const [stmts, next] = emitStatementAst(s, currentCtx);
|
|
46
|
+
allStatements.push(...stmts);
|
|
47
|
+
currentCtx = next;
|
|
48
|
+
}
|
|
49
|
+
return currentCtx;
|
|
50
|
+
};
|
|
51
|
+
const finalCtx = bodyStmt.kind === "blockStatement"
|
|
52
|
+
? emitBodyStatements(bodyStmt.statements, bodyCtx)
|
|
53
|
+
: (() => {
|
|
54
|
+
const [stmts, next] = emitStatementAst(bodyStmt, bodyCtx);
|
|
55
|
+
allStatements.push(...stmts);
|
|
56
|
+
return next;
|
|
57
|
+
})();
|
|
58
|
+
return [{ kind: "blockStatement", statements: allStatements }, finalCtx];
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Build a `var name = expr.AsN();` statement as AST.
|
|
62
|
+
*/
|
|
63
|
+
const buildCastLocalDecl = (varName, receiverName, memberN) => ({
|
|
64
|
+
kind: "localDeclarationStatement",
|
|
65
|
+
modifiers: [],
|
|
66
|
+
type: { kind: "varType" },
|
|
67
|
+
declarators: [
|
|
68
|
+
{
|
|
69
|
+
name: varName,
|
|
70
|
+
initializer: {
|
|
71
|
+
kind: "invocationExpression",
|
|
72
|
+
expression: {
|
|
73
|
+
kind: "memberAccessExpression",
|
|
74
|
+
expression: {
|
|
75
|
+
kind: "identifierExpression",
|
|
76
|
+
identifier: receiverName,
|
|
77
|
+
},
|
|
78
|
+
memberName: `As${memberN}`,
|
|
79
|
+
},
|
|
80
|
+
arguments: [],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
/**
|
|
86
|
+
* Build the condition expression `orig.IsN()` or `!orig.IsN()`.
|
|
87
|
+
*/
|
|
88
|
+
const buildIsNCondition = (escapedOrig, memberN, negate) => {
|
|
89
|
+
const isCall = {
|
|
90
|
+
kind: "invocationExpression",
|
|
91
|
+
expression: {
|
|
92
|
+
kind: "memberAccessExpression",
|
|
93
|
+
expression: { kind: "identifierExpression", identifier: escapedOrig },
|
|
94
|
+
memberName: `Is${memberN}`,
|
|
95
|
+
},
|
|
96
|
+
arguments: [],
|
|
97
|
+
};
|
|
98
|
+
return negate
|
|
99
|
+
? { kind: "prefixUnaryExpression", operatorToken: "!", operand: isCall }
|
|
100
|
+
: isCall;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Build the condition expression `orig is TypeName varName`.
|
|
104
|
+
*/
|
|
105
|
+
const buildIsPatternCondition = (escapedOrig, rhsTypeText, escapedNarrow) => ({
|
|
106
|
+
kind: "identifierExpression",
|
|
107
|
+
identifier: `${escapedOrig} is ${rhsTypeText} ${escapedNarrow}`,
|
|
108
|
+
});
|
|
109
|
+
/**
|
|
110
|
+
* Emit an if statement as AST
|
|
111
|
+
*/
|
|
112
|
+
export const emitIfStatementAst = (stmt, context) => {
|
|
113
|
+
// Case A: if (isUser(account)) { ... }
|
|
114
|
+
// Predicate narrowing rewrite → if (account.IsN()) { var account__N_k = account.AsN(); ... }
|
|
115
|
+
if (stmt.condition.kind === "call") {
|
|
116
|
+
const guard = tryResolvePredicateGuard(stmt.condition, context);
|
|
117
|
+
if (guard) {
|
|
118
|
+
const { memberN, ctxWithId, escapedOrig, escapedNarrow, narrowedMap } = guard;
|
|
119
|
+
const condAst = buildIsNCondition(escapedOrig, memberN, false);
|
|
120
|
+
const castStmt = buildCastLocalDecl(escapedNarrow, escapedOrig, memberN);
|
|
121
|
+
const thenCtx = {
|
|
122
|
+
...ctxWithId,
|
|
123
|
+
narrowedBindings: narrowedMap,
|
|
124
|
+
};
|
|
125
|
+
const [thenBlock, thenBodyCtx] = emitForcedBlockWithPreambleAst([castStmt], stmt.thenStatement, thenCtx);
|
|
126
|
+
let finalContext = {
|
|
127
|
+
...thenBodyCtx,
|
|
128
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
129
|
+
};
|
|
130
|
+
let elseStmt;
|
|
131
|
+
if (stmt.elseStatement) {
|
|
132
|
+
const [elseStmts, elseCtx] = emitStatementAst(stmt.elseStatement, finalContext);
|
|
133
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
134
|
+
finalContext = elseCtx;
|
|
135
|
+
}
|
|
136
|
+
const ifStmt = {
|
|
137
|
+
kind: "ifStatement",
|
|
138
|
+
condition: condAst,
|
|
139
|
+
thenStatement: thenBlock,
|
|
140
|
+
elseStatement: elseStmt,
|
|
141
|
+
};
|
|
142
|
+
return [[ifStmt], finalContext];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Case A3: if ("error" in auth) { ... }
|
|
146
|
+
// Union 'in' narrowing rewrite → if (auth.IsN()) { var auth__N_k = auth.AsN(); ... }
|
|
147
|
+
const inGuard = tryResolveInGuard(stmt.condition, context);
|
|
148
|
+
if (inGuard) {
|
|
149
|
+
const { originalName, memberN, unionArity, ctxWithId, escapedOrig, escapedNarrow, narrowedMap, } = inGuard;
|
|
150
|
+
const condAst = buildIsNCondition(escapedOrig, memberN, false);
|
|
151
|
+
const castStmt = buildCastLocalDecl(escapedNarrow, escapedOrig, memberN);
|
|
152
|
+
const thenCtx = {
|
|
153
|
+
...ctxWithId,
|
|
154
|
+
narrowedBindings: narrowedMap,
|
|
155
|
+
};
|
|
156
|
+
const [thenBlock, thenBodyCtx] = emitForcedBlockWithPreambleAst([castStmt], stmt.thenStatement, thenCtx);
|
|
157
|
+
let finalContext = thenBodyCtx;
|
|
158
|
+
let elseStmt;
|
|
159
|
+
if (stmt.elseStatement) {
|
|
160
|
+
if (unionArity === 2) {
|
|
161
|
+
const otherMemberN = memberN === 1 ? 2 : 1;
|
|
162
|
+
const exprAst = buildUnionNarrowAst(escapedOrig, otherMemberN);
|
|
163
|
+
const elseNarrowedMap = new Map(ctxWithId.narrowedBindings ?? []);
|
|
164
|
+
elseNarrowedMap.set(originalName, { kind: "expr", exprAst });
|
|
165
|
+
const elseCtx = {
|
|
166
|
+
...finalContext,
|
|
167
|
+
narrowedBindings: elseNarrowedMap,
|
|
168
|
+
};
|
|
169
|
+
const [elseStmts, elseCtxAfter] = emitStatementAst(stmt.elseStatement, elseCtx);
|
|
170
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
171
|
+
finalContext = {
|
|
172
|
+
...elseCtxAfter,
|
|
173
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
174
|
+
};
|
|
175
|
+
return [
|
|
176
|
+
[
|
|
177
|
+
{
|
|
178
|
+
kind: "ifStatement",
|
|
179
|
+
condition: condAst,
|
|
180
|
+
thenStatement: thenBlock,
|
|
181
|
+
elseStatement: elseStmt,
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
finalContext,
|
|
185
|
+
];
|
|
186
|
+
}
|
|
187
|
+
// Can't narrow ELSE safely, emit without narrowing.
|
|
188
|
+
const [elseStmts, elseCtx] = emitStatementAst(stmt.elseStatement, {
|
|
189
|
+
...finalContext,
|
|
190
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
191
|
+
});
|
|
192
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
193
|
+
finalContext = {
|
|
194
|
+
...elseCtx,
|
|
195
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
196
|
+
};
|
|
197
|
+
return [
|
|
198
|
+
[
|
|
199
|
+
{
|
|
200
|
+
kind: "ifStatement",
|
|
201
|
+
condition: condAst,
|
|
202
|
+
thenStatement: thenBlock,
|
|
203
|
+
elseStatement: elseStmt,
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
finalContext,
|
|
207
|
+
];
|
|
208
|
+
}
|
|
209
|
+
// Post-if narrowing for early-exit patterns (2-member unions only)
|
|
210
|
+
if (unionArity === 2 && isDefinitelyTerminating(stmt.thenStatement)) {
|
|
211
|
+
const otherMemberN = memberN === 1 ? 2 : 1;
|
|
212
|
+
const exprAst = buildUnionNarrowAst(escapedOrig, otherMemberN);
|
|
213
|
+
const postMap = new Map(ctxWithId.narrowedBindings ?? []);
|
|
214
|
+
postMap.set(originalName, { kind: "expr", exprAst });
|
|
215
|
+
finalContext = { ...finalContext, narrowedBindings: postMap };
|
|
216
|
+
return [
|
|
217
|
+
[{ kind: "ifStatement", condition: condAst, thenStatement: thenBlock }],
|
|
218
|
+
finalContext,
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
finalContext = {
|
|
222
|
+
...finalContext,
|
|
223
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
224
|
+
};
|
|
225
|
+
return [
|
|
226
|
+
[{ kind: "ifStatement", condition: condAst, thenStatement: thenBlock }],
|
|
227
|
+
finalContext,
|
|
228
|
+
];
|
|
229
|
+
}
|
|
230
|
+
// Case A4: if (shape.kind === "circle") { ... }
|
|
231
|
+
// Discriminant literal equality narrowing
|
|
232
|
+
const eqGuard = tryResolveDiscriminantEqualityGuard(stmt.condition, context);
|
|
233
|
+
if (eqGuard) {
|
|
234
|
+
const { originalName, operator, memberN, unionArity, ctxWithId, escapedOrig, escapedNarrow, narrowedMap, } = eqGuard;
|
|
235
|
+
const isInequality = operator === "!==" || operator === "!=";
|
|
236
|
+
const condAst = buildIsNCondition(escapedOrig, memberN, isInequality);
|
|
237
|
+
let finalContext = ctxWithId;
|
|
238
|
+
// Equality: narrow THEN to memberN. Inequality: narrow ELSE to memberN.
|
|
239
|
+
if (!isInequality) {
|
|
240
|
+
const castStmt = buildCastLocalDecl(escapedNarrow, escapedOrig, memberN);
|
|
241
|
+
const thenCtx = {
|
|
242
|
+
...ctxWithId,
|
|
243
|
+
narrowedBindings: narrowedMap,
|
|
244
|
+
};
|
|
245
|
+
const [thenBlock, thenBodyCtx] = emitForcedBlockWithPreambleAst([castStmt], stmt.thenStatement, thenCtx);
|
|
246
|
+
finalContext = thenBodyCtx;
|
|
247
|
+
let elseStmt;
|
|
248
|
+
if (stmt.elseStatement) {
|
|
249
|
+
if (unionArity === 2) {
|
|
250
|
+
const otherMemberN = memberN === 1 ? 2 : 1;
|
|
251
|
+
const exprAst = buildUnionNarrowAst(escapedOrig, otherMemberN);
|
|
252
|
+
const elseNarrowedMap = new Map(ctxWithId.narrowedBindings ?? []);
|
|
253
|
+
elseNarrowedMap.set(originalName, { kind: "expr", exprAst });
|
|
254
|
+
const [elseStmts, elseCtxAfter] = emitStatementAst(stmt.elseStatement, { ...finalContext, narrowedBindings: elseNarrowedMap });
|
|
255
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
256
|
+
finalContext = {
|
|
257
|
+
...elseCtxAfter,
|
|
258
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
259
|
+
};
|
|
260
|
+
return [
|
|
261
|
+
[
|
|
262
|
+
{
|
|
263
|
+
kind: "ifStatement",
|
|
264
|
+
condition: condAst,
|
|
265
|
+
thenStatement: thenBlock,
|
|
266
|
+
elseStatement: elseStmt,
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
finalContext,
|
|
270
|
+
];
|
|
271
|
+
}
|
|
272
|
+
const [elseStmts, elseCtx] = emitStatementAst(stmt.elseStatement, {
|
|
273
|
+
...finalContext,
|
|
274
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
275
|
+
});
|
|
276
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
277
|
+
finalContext = {
|
|
278
|
+
...elseCtx,
|
|
279
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
280
|
+
};
|
|
281
|
+
return [
|
|
282
|
+
[
|
|
283
|
+
{
|
|
284
|
+
kind: "ifStatement",
|
|
285
|
+
condition: condAst,
|
|
286
|
+
thenStatement: thenBlock,
|
|
287
|
+
elseStatement: elseStmt,
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
finalContext,
|
|
291
|
+
];
|
|
292
|
+
}
|
|
293
|
+
// Post-if narrowing for early-exit patterns (2-member unions only)
|
|
294
|
+
if (unionArity === 2 && isDefinitelyTerminating(stmt.thenStatement)) {
|
|
295
|
+
const otherMemberN = memberN === 1 ? 2 : 1;
|
|
296
|
+
const exprAst = buildUnionNarrowAst(escapedOrig, otherMemberN);
|
|
297
|
+
const postMap = new Map(ctxWithId.narrowedBindings ?? []);
|
|
298
|
+
postMap.set(originalName, { kind: "expr", exprAst });
|
|
299
|
+
finalContext = { ...finalContext, narrowedBindings: postMap };
|
|
300
|
+
return [
|
|
301
|
+
[
|
|
302
|
+
{
|
|
303
|
+
kind: "ifStatement",
|
|
304
|
+
condition: condAst,
|
|
305
|
+
thenStatement: thenBlock,
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
finalContext,
|
|
309
|
+
];
|
|
310
|
+
}
|
|
311
|
+
finalContext = {
|
|
312
|
+
...finalContext,
|
|
313
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
314
|
+
};
|
|
315
|
+
return [
|
|
316
|
+
[{ kind: "ifStatement", condition: condAst, thenStatement: thenBlock }],
|
|
317
|
+
finalContext,
|
|
318
|
+
];
|
|
319
|
+
}
|
|
320
|
+
// Inequality: THEN is "not memberN", ELSE is memberN
|
|
321
|
+
{
|
|
322
|
+
let thenStmt;
|
|
323
|
+
let thenCtx;
|
|
324
|
+
if (unionArity === 2) {
|
|
325
|
+
const otherMemberN = memberN === 1 ? 2 : 1;
|
|
326
|
+
const exprAst = buildUnionNarrowAst(escapedOrig, otherMemberN);
|
|
327
|
+
const thenNarrowedMap = new Map(ctxWithId.narrowedBindings ?? []);
|
|
328
|
+
thenNarrowedMap.set(originalName, { kind: "expr", exprAst });
|
|
329
|
+
const [thenStmts, thenCtxAfter] = emitStatementAst(stmt.thenStatement, {
|
|
330
|
+
...ctxWithId,
|
|
331
|
+
narrowedBindings: thenNarrowedMap,
|
|
332
|
+
});
|
|
333
|
+
thenStmt = wrapInBlock(thenStmts);
|
|
334
|
+
thenCtx = thenCtxAfter;
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
const [thenStmts, thenCtxAfter] = emitStatementAst(stmt.thenStatement, ctxWithId);
|
|
338
|
+
thenStmt = wrapInBlock(thenStmts);
|
|
339
|
+
thenCtx = thenCtxAfter;
|
|
340
|
+
}
|
|
341
|
+
finalContext = thenCtx;
|
|
342
|
+
let elseStmt;
|
|
343
|
+
if (stmt.elseStatement) {
|
|
344
|
+
const castStmt = buildCastLocalDecl(escapedNarrow, escapedOrig, memberN);
|
|
345
|
+
const [elseBlock, elseBodyCtx] = emitForcedBlockWithPreambleAst([castStmt], stmt.elseStatement, { ...ctxWithId, narrowedBindings: narrowedMap });
|
|
346
|
+
elseStmt = elseBlock;
|
|
347
|
+
finalContext = {
|
|
348
|
+
...elseBodyCtx,
|
|
349
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
350
|
+
};
|
|
351
|
+
return [
|
|
352
|
+
[
|
|
353
|
+
{
|
|
354
|
+
kind: "ifStatement",
|
|
355
|
+
condition: condAst,
|
|
356
|
+
thenStatement: thenStmt,
|
|
357
|
+
elseStatement: elseStmt,
|
|
358
|
+
},
|
|
359
|
+
],
|
|
360
|
+
finalContext,
|
|
361
|
+
];
|
|
362
|
+
}
|
|
363
|
+
// Post-if narrowing for early-exit patterns
|
|
364
|
+
if (unionArity === 2 && isDefinitelyTerminating(stmt.thenStatement)) {
|
|
365
|
+
const exprAst = buildUnionNarrowAst(escapedOrig, memberN);
|
|
366
|
+
const postMap = new Map(ctxWithId.narrowedBindings ?? []);
|
|
367
|
+
postMap.set(originalName, { kind: "expr", exprAst });
|
|
368
|
+
finalContext = { ...finalContext, narrowedBindings: postMap };
|
|
369
|
+
return [
|
|
370
|
+
[
|
|
371
|
+
{
|
|
372
|
+
kind: "ifStatement",
|
|
373
|
+
condition: condAst,
|
|
374
|
+
thenStatement: thenStmt,
|
|
375
|
+
},
|
|
376
|
+
],
|
|
377
|
+
finalContext,
|
|
378
|
+
];
|
|
379
|
+
}
|
|
380
|
+
finalContext = {
|
|
381
|
+
...finalContext,
|
|
382
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
383
|
+
};
|
|
384
|
+
return [
|
|
385
|
+
[{ kind: "ifStatement", condition: condAst, thenStatement: thenStmt }],
|
|
386
|
+
finalContext,
|
|
387
|
+
];
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// Case A2: if (x instanceof Foo) { ... }
|
|
391
|
+
// C# pattern var narrowing → if (x is Foo x__is_k) { ... }
|
|
392
|
+
const instanceofGuard = tryResolveInstanceofGuard(stmt.condition, context);
|
|
393
|
+
if (instanceofGuard) {
|
|
394
|
+
const { ctxAfterRhs, escapedOrig, escapedNarrow, rhsTypeText, narrowedMap, } = instanceofGuard;
|
|
395
|
+
const condAst = buildIsPatternCondition(escapedOrig, rhsTypeText, escapedNarrow);
|
|
396
|
+
const thenCtx = {
|
|
397
|
+
...ctxAfterRhs,
|
|
398
|
+
narrowedBindings: narrowedMap,
|
|
399
|
+
};
|
|
400
|
+
const [thenStmts, thenCtxAfter] = emitStatementAst(stmt.thenStatement, thenCtx);
|
|
401
|
+
let finalContext = {
|
|
402
|
+
...thenCtxAfter,
|
|
403
|
+
narrowedBindings: ctxAfterRhs.narrowedBindings,
|
|
404
|
+
};
|
|
405
|
+
let elseStmt;
|
|
406
|
+
if (stmt.elseStatement) {
|
|
407
|
+
const [elseStmts, elseCtx] = emitStatementAst(stmt.elseStatement, finalContext);
|
|
408
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
409
|
+
finalContext = elseCtx;
|
|
410
|
+
}
|
|
411
|
+
return [
|
|
412
|
+
[
|
|
413
|
+
{
|
|
414
|
+
kind: "ifStatement",
|
|
415
|
+
condition: condAst,
|
|
416
|
+
thenStatement: wrapInBlock(thenStmts),
|
|
417
|
+
elseStatement: elseStmt,
|
|
418
|
+
},
|
|
419
|
+
],
|
|
420
|
+
finalContext,
|
|
421
|
+
];
|
|
422
|
+
}
|
|
423
|
+
// Case B: if (!isUser(account)) { ... } else { ... }
|
|
424
|
+
// Negated guard → for 2-member unions, narrow THEN to OTHER member, ELSE to guard's target
|
|
425
|
+
if (stmt.condition.kind === "unary" &&
|
|
426
|
+
stmt.condition.operator === "!" &&
|
|
427
|
+
stmt.condition.expression.kind === "call" &&
|
|
428
|
+
stmt.elseStatement) {
|
|
429
|
+
const innerCall = stmt.condition.expression;
|
|
430
|
+
const guard = tryResolvePredicateGuard(innerCall, context);
|
|
431
|
+
if (guard) {
|
|
432
|
+
const { originalName, memberN, unionArity, ctxWithId, escapedOrig, escapedNarrow, narrowedMap, } = guard;
|
|
433
|
+
const condAst = buildIsNCondition(escapedOrig, memberN, true);
|
|
434
|
+
// THEN branch: for 2-member unions narrow to OTHER member
|
|
435
|
+
let thenStmt;
|
|
436
|
+
let thenCtx;
|
|
437
|
+
if (unionArity === 2) {
|
|
438
|
+
const otherMemberN = memberN === 1 ? 2 : 1;
|
|
439
|
+
const nextId = (ctxWithId.tempVarId ?? 0) + 1;
|
|
440
|
+
const thenCtxWithId = {
|
|
441
|
+
...ctxWithId,
|
|
442
|
+
tempVarId: nextId,
|
|
443
|
+
};
|
|
444
|
+
const thenNarrowedName = `${originalName}__${otherMemberN}_${nextId}`;
|
|
445
|
+
const escapedThenNarrow = escapeCSharpIdentifier(thenNarrowedName);
|
|
446
|
+
const thenNarrowedMap = new Map(thenCtxWithId.narrowedBindings ?? []);
|
|
447
|
+
thenNarrowedMap.set(originalName, {
|
|
448
|
+
kind: "rename",
|
|
449
|
+
name: thenNarrowedName,
|
|
450
|
+
});
|
|
451
|
+
const thenCastStmt = buildCastLocalDecl(escapedThenNarrow, escapedOrig, otherMemberN);
|
|
452
|
+
const [thenBlock, thenBlockCtx] = emitForcedBlockWithPreambleAst([thenCastStmt], stmt.thenStatement, { ...thenCtxWithId, narrowedBindings: thenNarrowedMap });
|
|
453
|
+
thenStmt = thenBlock;
|
|
454
|
+
thenCtx = thenBlockCtx;
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
const [thenStmts, thenCtxAfter] = emitStatementAst(stmt.thenStatement, context);
|
|
458
|
+
thenStmt = wrapInBlock(thenStmts);
|
|
459
|
+
thenCtx = thenCtxAfter;
|
|
460
|
+
}
|
|
461
|
+
// ELSE branch: narrowing applies (to guard's target type)
|
|
462
|
+
const elseCastStmt = buildCastLocalDecl(escapedNarrow, escapedOrig, memberN);
|
|
463
|
+
const [elseBlock, _elseBodyCtx] = emitForcedBlockWithPreambleAst([elseCastStmt], stmt.elseStatement, { ...ctxWithId, narrowedBindings: narrowedMap });
|
|
464
|
+
return [
|
|
465
|
+
[
|
|
466
|
+
{
|
|
467
|
+
kind: "ifStatement",
|
|
468
|
+
condition: condAst,
|
|
469
|
+
thenStatement: thenStmt,
|
|
470
|
+
elseStatement: elseBlock,
|
|
471
|
+
},
|
|
472
|
+
],
|
|
473
|
+
thenCtx,
|
|
474
|
+
];
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
// Case B2: if (!(x instanceof Foo)) { ... } else { ... }
|
|
478
|
+
// Swap branches so ELSE runs under the narrowed pattern var.
|
|
479
|
+
if (stmt.condition.kind === "unary" &&
|
|
480
|
+
stmt.condition.operator === "!" &&
|
|
481
|
+
stmt.elseStatement) {
|
|
482
|
+
const inner = stmt.condition.expression;
|
|
483
|
+
const guard = tryResolveInstanceofGuard(inner, context);
|
|
484
|
+
if (guard) {
|
|
485
|
+
const { ctxAfterRhs, escapedOrig, escapedNarrow, rhsTypeText, narrowedMap, } = guard;
|
|
486
|
+
const condAst = buildIsPatternCondition(escapedOrig, rhsTypeText, escapedNarrow);
|
|
487
|
+
// THEN branch is the original ELSE (narrowed)
|
|
488
|
+
const thenCtx = {
|
|
489
|
+
...ctxAfterRhs,
|
|
490
|
+
narrowedBindings: narrowedMap,
|
|
491
|
+
};
|
|
492
|
+
const [thenStmts, thenCtxAfter] = emitStatementAst(stmt.elseStatement, thenCtx);
|
|
493
|
+
// ELSE branch is the original THEN (not narrowed)
|
|
494
|
+
const [elseStmts, elseCtxAfter] = emitStatementAst(stmt.thenStatement, {
|
|
495
|
+
...thenCtxAfter,
|
|
496
|
+
narrowedBindings: ctxAfterRhs.narrowedBindings,
|
|
497
|
+
});
|
|
498
|
+
return [
|
|
499
|
+
[
|
|
500
|
+
{
|
|
501
|
+
kind: "ifStatement",
|
|
502
|
+
condition: condAst,
|
|
503
|
+
thenStatement: wrapInBlock(thenStmts),
|
|
504
|
+
elseStatement: wrapInBlock(elseStmts),
|
|
505
|
+
},
|
|
506
|
+
],
|
|
507
|
+
elseCtxAfter,
|
|
508
|
+
];
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// Case C: if (isUser(account) && account.foo) { ... }
|
|
512
|
+
// Logical AND with predicate guard on left → nested-if lowering
|
|
513
|
+
if (stmt.condition.kind === "logical" && stmt.condition.operator === "&&") {
|
|
514
|
+
const left = stmt.condition.left;
|
|
515
|
+
const right = stmt.condition.right;
|
|
516
|
+
if (left.kind === "call") {
|
|
517
|
+
const guard = tryResolvePredicateGuard(left, context);
|
|
518
|
+
if (guard) {
|
|
519
|
+
const { memberN, ctxWithId, escapedOrig, escapedNarrow, narrowedMap } = guard;
|
|
520
|
+
const outerCondAst = buildIsNCondition(escapedOrig, memberN, false);
|
|
521
|
+
const castStmt = buildCastLocalDecl(escapedNarrow, escapedOrig, memberN);
|
|
522
|
+
// Emit RHS condition under narrowed context
|
|
523
|
+
const outerThenCtx = {
|
|
524
|
+
...ctxWithId,
|
|
525
|
+
narrowedBindings: narrowedMap,
|
|
526
|
+
};
|
|
527
|
+
const [rhsAst, rhsCtxAfterEmit] = emitExpressionAst(right, outerThenCtx);
|
|
528
|
+
const [rhsCondAst, rhsCtxAfterCond] = toBooleanConditionAst(right, rhsAst, rhsCtxAfterEmit);
|
|
529
|
+
// When RHS true: emit original THEN under narrowed context
|
|
530
|
+
const [thenStmts, thenCtxAfter] = emitStatementAst(stmt.thenStatement, rhsCtxAfterCond);
|
|
531
|
+
const clearNarrowing = (ctx) => ({
|
|
532
|
+
...ctx,
|
|
533
|
+
narrowedBindings: ctxWithId.narrowedBindings,
|
|
534
|
+
});
|
|
535
|
+
// Build inner if
|
|
536
|
+
let innerElse;
|
|
537
|
+
let currentCtx = thenCtxAfter;
|
|
538
|
+
if (stmt.elseStatement) {
|
|
539
|
+
const [innerElseStmts, innerElseCtx] = emitStatementAst(stmt.elseStatement, clearNarrowing(currentCtx));
|
|
540
|
+
innerElse = wrapInBlock(innerElseStmts);
|
|
541
|
+
currentCtx = innerElseCtx;
|
|
542
|
+
}
|
|
543
|
+
const innerIf = {
|
|
544
|
+
kind: "ifStatement",
|
|
545
|
+
condition: rhsCondAst,
|
|
546
|
+
thenStatement: wrapInBlock(thenStmts),
|
|
547
|
+
elseStatement: innerElse,
|
|
548
|
+
};
|
|
549
|
+
// Build outer then block: { cast; innerIf }
|
|
550
|
+
const outerThenBlock = {
|
|
551
|
+
kind: "blockStatement",
|
|
552
|
+
statements: [castStmt, innerIf],
|
|
553
|
+
};
|
|
554
|
+
// Outer else: emit ELSE as-is (no narrowing)
|
|
555
|
+
let outerElse;
|
|
556
|
+
let finalContext = clearNarrowing(currentCtx);
|
|
557
|
+
if (stmt.elseStatement) {
|
|
558
|
+
const [outerElseStmts, outerElseCtx] = emitStatementAst(stmt.elseStatement, finalContext);
|
|
559
|
+
outerElse = wrapInBlock(outerElseStmts);
|
|
560
|
+
finalContext = outerElseCtx;
|
|
561
|
+
}
|
|
562
|
+
return [
|
|
563
|
+
[
|
|
564
|
+
{
|
|
565
|
+
kind: "ifStatement",
|
|
566
|
+
condition: outerCondAst,
|
|
567
|
+
thenStatement: outerThenBlock,
|
|
568
|
+
elseStatement: outerElse,
|
|
569
|
+
},
|
|
570
|
+
],
|
|
571
|
+
finalContext,
|
|
572
|
+
];
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
// Case C2: if (x instanceof Foo && x.foo) { ... }
|
|
576
|
+
if (left.kind === "binary" && left.operator === "instanceof") {
|
|
577
|
+
const guard = tryResolveInstanceofGuard(left, context);
|
|
578
|
+
if (guard) {
|
|
579
|
+
const { ctxAfterRhs, escapedOrig, escapedNarrow, rhsTypeText, narrowedMap, } = guard;
|
|
580
|
+
const rhsCtx = {
|
|
581
|
+
...ctxAfterRhs,
|
|
582
|
+
narrowedBindings: narrowedMap,
|
|
583
|
+
};
|
|
584
|
+
const [rhsAst, rhsCtxAfterEmit] = emitExpressionAst(right, rhsCtx);
|
|
585
|
+
const [rhsCondAst, rhsCtxAfterCond] = toBooleanConditionAst(right, rhsAst, rhsCtxAfterEmit);
|
|
586
|
+
// Combined condition: (orig is TypeName narrow && rhsCond)
|
|
587
|
+
const isPatternAst = buildIsPatternCondition(escapedOrig, rhsTypeText, escapedNarrow);
|
|
588
|
+
const combinedCondAst = {
|
|
589
|
+
kind: "parenthesizedExpression",
|
|
590
|
+
expression: {
|
|
591
|
+
kind: "binaryExpression",
|
|
592
|
+
operatorToken: "&&",
|
|
593
|
+
left: isPatternAst,
|
|
594
|
+
right: rhsCondAst,
|
|
595
|
+
},
|
|
596
|
+
};
|
|
597
|
+
const thenCtx = {
|
|
598
|
+
...rhsCtxAfterCond,
|
|
599
|
+
narrowedBindings: narrowedMap,
|
|
600
|
+
};
|
|
601
|
+
const [thenStmts, thenCtxAfter] = emitStatementAst(stmt.thenStatement, thenCtx);
|
|
602
|
+
let finalContext = {
|
|
603
|
+
...thenCtxAfter,
|
|
604
|
+
narrowedBindings: ctxAfterRhs.narrowedBindings,
|
|
605
|
+
};
|
|
606
|
+
let elseStmt;
|
|
607
|
+
if (stmt.elseStatement) {
|
|
608
|
+
const [elseStmts, elseCtx] = emitStatementAst(stmt.elseStatement, finalContext);
|
|
609
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
610
|
+
finalContext = elseCtx;
|
|
611
|
+
}
|
|
612
|
+
return [
|
|
613
|
+
[
|
|
614
|
+
{
|
|
615
|
+
kind: "ifStatement",
|
|
616
|
+
condition: combinedCondAst,
|
|
617
|
+
thenStatement: wrapInBlock(thenStmts),
|
|
618
|
+
elseStatement: elseStmt,
|
|
619
|
+
},
|
|
620
|
+
],
|
|
621
|
+
finalContext,
|
|
622
|
+
];
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
// Case D: Nullable value type narrowing
|
|
627
|
+
// if (id !== null) { ... } → id becomes id.Value in then-branch
|
|
628
|
+
const simpleNullableGuard = tryResolveSimpleNullableGuard(stmt.condition);
|
|
629
|
+
const nullableGuard = simpleNullableGuard ?? tryResolveNullableGuard(stmt.condition, context);
|
|
630
|
+
if (nullableGuard && nullableGuard.isValueType) {
|
|
631
|
+
const { key, targetExpr, narrowsInThen, strippedType } = nullableGuard;
|
|
632
|
+
// Avoid stacking `.Value` (see detailed comment in original text emitter)
|
|
633
|
+
const [idAst] = targetExpr.kind === "identifier"
|
|
634
|
+
? emitIdentifier(targetExpr, {
|
|
635
|
+
...context,
|
|
636
|
+
narrowedBindings: undefined,
|
|
637
|
+
})
|
|
638
|
+
: emitExpressionAst(targetExpr, {
|
|
639
|
+
...context,
|
|
640
|
+
narrowedBindings: undefined,
|
|
641
|
+
});
|
|
642
|
+
// Create narrowed binding: id → id.Value
|
|
643
|
+
const narrowedMap = new Map(context.narrowedBindings ?? []);
|
|
644
|
+
narrowedMap.set(key, {
|
|
645
|
+
kind: "expr",
|
|
646
|
+
exprAst: {
|
|
647
|
+
kind: "memberAccessExpression",
|
|
648
|
+
expression: idAst,
|
|
649
|
+
memberName: "Value",
|
|
650
|
+
},
|
|
651
|
+
type: strippedType,
|
|
652
|
+
});
|
|
653
|
+
// Soundness: In compound conditions (A && B), we must NOT apply "else" narrowing.
|
|
654
|
+
const isAndCondition = stmt.condition.kind === "logical" && stmt.condition.operator === "&&";
|
|
655
|
+
if (isAndCondition && !simpleNullableGuard && !narrowsInThen) {
|
|
656
|
+
// `id == null` inside `&&` - skip nullable rewrite, fall through to standard.
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
// Emit condition
|
|
660
|
+
const [condAst, condCtxAfterCond] = emitBooleanConditionAst(stmt.condition, emitExprAstCb, context);
|
|
661
|
+
// Apply narrowing to appropriate branch
|
|
662
|
+
const thenCtx = {
|
|
663
|
+
...condCtxAfterCond,
|
|
664
|
+
narrowedBindings: narrowsInThen
|
|
665
|
+
? narrowedMap
|
|
666
|
+
: condCtxAfterCond.narrowedBindings,
|
|
667
|
+
};
|
|
668
|
+
const [thenStmts, thenCtxAfter] = emitStatementAst(stmt.thenStatement, thenCtx);
|
|
669
|
+
let finalContext = {
|
|
670
|
+
...thenCtxAfter,
|
|
671
|
+
narrowedBindings: context.narrowedBindings,
|
|
672
|
+
};
|
|
673
|
+
let elseStmt;
|
|
674
|
+
if (stmt.elseStatement) {
|
|
675
|
+
const elseCtx = {
|
|
676
|
+
...finalContext,
|
|
677
|
+
narrowedBindings: !narrowsInThen
|
|
678
|
+
? simpleNullableGuard
|
|
679
|
+
? narrowedMap
|
|
680
|
+
: context.narrowedBindings
|
|
681
|
+
: context.narrowedBindings,
|
|
682
|
+
};
|
|
683
|
+
const [elseStmts, elseCtxAfter] = emitStatementAst(stmt.elseStatement, elseCtx);
|
|
684
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
685
|
+
finalContext = {
|
|
686
|
+
...elseCtxAfter,
|
|
687
|
+
narrowedBindings: context.narrowedBindings,
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
return [
|
|
691
|
+
[
|
|
692
|
+
{
|
|
693
|
+
kind: "ifStatement",
|
|
694
|
+
condition: condAst,
|
|
695
|
+
thenStatement: wrapInBlock(thenStmts),
|
|
696
|
+
elseStatement: elseStmt,
|
|
697
|
+
},
|
|
698
|
+
],
|
|
699
|
+
finalContext,
|
|
700
|
+
];
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
// Standard if-statement emission (no narrowing)
|
|
704
|
+
const [condAst, condCtxAfterCond] = emitBooleanConditionAst(stmt.condition, emitExprAstCb, context);
|
|
705
|
+
const [thenStmts, thenContext] = emitStatementAst(stmt.thenStatement, condCtxAfterCond);
|
|
706
|
+
let finalContext = thenContext;
|
|
707
|
+
let elseStmt;
|
|
708
|
+
if (stmt.elseStatement) {
|
|
709
|
+
const [elseStmts, elseContext] = emitStatementAst(stmt.elseStatement, finalContext);
|
|
710
|
+
elseStmt = wrapInBlock(elseStmts);
|
|
711
|
+
finalContext = elseContext;
|
|
712
|
+
}
|
|
713
|
+
return [
|
|
714
|
+
[
|
|
715
|
+
{
|
|
716
|
+
kind: "ifStatement",
|
|
717
|
+
condition: condAst,
|
|
718
|
+
thenStatement: wrapInBlock(thenStmts),
|
|
719
|
+
elseStatement: elseStmt,
|
|
720
|
+
},
|
|
721
|
+
],
|
|
722
|
+
finalContext,
|
|
723
|
+
];
|
|
724
|
+
};
|
|
725
|
+
//# sourceMappingURL=if-emitter.js.map
|