eslint 9.22.0 → 9.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -46
- package/bin/eslint.js +92 -90
- package/conf/default-cli-options.js +22 -22
- package/conf/ecma-version.js +1 -1
- package/conf/globals.js +97 -98
- package/conf/replacements.json +24 -20
- package/conf/rule-type-list.json +88 -92
- package/lib/api.js +12 -12
- package/lib/cli-engine/cli-engine.js +830 -810
- package/lib/cli-engine/file-enumerator.js +381 -387
- package/lib/cli-engine/formatters/formatters-meta.json +16 -16
- package/lib/cli-engine/formatters/html.js +107 -99
- package/lib/cli-engine/formatters/json-with-metadata.js +5 -5
- package/lib/cli-engine/formatters/json.js +2 -2
- package/lib/cli-engine/formatters/stylish.js +96 -75
- package/lib/cli-engine/hash.js +1 -1
- package/lib/cli-engine/index.js +1 -1
- package/lib/cli-engine/lint-result-cache.js +144 -145
- package/lib/cli-engine/load-rules.js +16 -16
- package/lib/cli.js +638 -457
- package/lib/config/config-loader.js +726 -622
- package/lib/config/config.js +247 -221
- package/lib/config/default-config.js +54 -45
- package/lib/config/flat-config-array.js +167 -172
- package/lib/config/flat-config-helpers.js +72 -72
- package/lib/config/flat-config-schema.js +375 -368
- package/lib/config/rule-validator.js +139 -144
- package/lib/config-api.js +2 -2
- package/lib/eslint/eslint-helpers.js +756 -681
- package/lib/eslint/eslint.js +934 -912
- package/lib/eslint/index.js +2 -2
- package/lib/eslint/legacy-eslint.js +577 -533
- package/lib/languages/js/index.js +263 -264
- package/lib/languages/js/source-code/index.js +1 -1
- package/lib/languages/js/source-code/source-code.js +1128 -1057
- package/lib/languages/js/source-code/token-store/backward-token-comment-cursor.js +39 -35
- package/lib/languages/js/source-code/token-store/backward-token-cursor.js +35 -36
- package/lib/languages/js/source-code/token-store/cursor.js +36 -36
- package/lib/languages/js/source-code/token-store/cursors.js +80 -52
- package/lib/languages/js/source-code/token-store/decorative-cursor.js +17 -18
- package/lib/languages/js/source-code/token-store/filter-cursor.js +19 -20
- package/lib/languages/js/source-code/token-store/forward-token-comment-cursor.js +40 -32
- package/lib/languages/js/source-code/token-store/forward-token-cursor.js +40 -41
- package/lib/languages/js/source-code/token-store/index.js +592 -498
- package/lib/languages/js/source-code/token-store/limit-cursor.js +17 -18
- package/lib/languages/js/source-code/token-store/padded-token-cursor.js +23 -16
- package/lib/languages/js/source-code/token-store/skip-cursor.js +19 -20
- package/lib/languages/js/source-code/token-store/utils.js +63 -60
- package/lib/languages/js/validate-language-options.js +104 -89
- package/lib/linter/apply-disable-directives.js +467 -383
- package/lib/linter/code-path-analysis/code-path-analyzer.js +650 -672
- package/lib/linter/code-path-analysis/code-path-segment.js +215 -216
- package/lib/linter/code-path-analysis/code-path-state.js +2118 -2096
- package/lib/linter/code-path-analysis/code-path.js +307 -319
- package/lib/linter/code-path-analysis/debug-helpers.js +183 -163
- package/lib/linter/code-path-analysis/fork-context.js +296 -271
- package/lib/linter/code-path-analysis/id-generator.js +22 -23
- package/lib/linter/file-context.js +119 -120
- package/lib/linter/index.js +3 -3
- package/lib/linter/interpolate.js +16 -16
- package/lib/linter/linter.js +2403 -2045
- package/lib/linter/node-event-generator.js +284 -225
- package/lib/linter/report-translator.js +256 -219
- package/lib/linter/rule-fixer.js +122 -124
- package/lib/linter/rules.js +36 -36
- package/lib/linter/safe-emitter.js +18 -18
- package/lib/linter/source-code-fixer.js +94 -92
- package/lib/linter/timing.js +104 -101
- package/lib/linter/vfile.js +70 -73
- package/lib/options.js +404 -361
- package/lib/rule-tester/index.js +1 -1
- package/lib/rule-tester/rule-tester.js +1308 -1046
- package/lib/rules/accessor-pairs.js +298 -263
- package/lib/rules/array-bracket-newline.js +250 -238
- package/lib/rules/array-bracket-spacing.js +263 -224
- package/lib/rules/array-callback-return.js +402 -356
- package/lib/rules/array-element-newline.js +358 -313
- package/lib/rules/arrow-body-style.js +400 -281
- package/lib/rules/arrow-parens.js +206 -173
- package/lib/rules/arrow-spacing.js +169 -163
- package/lib/rules/block-scoped-var.js +125 -123
- package/lib/rules/block-spacing.js +186 -176
- package/lib/rules/brace-style.js +262 -199
- package/lib/rules/callback-return.js +203 -190
- package/lib/rules/camelcase.js +403 -392
- package/lib/rules/capitalized-comments.js +253 -232
- package/lib/rules/class-methods-use-this.js +224 -172
- package/lib/rules/comma-dangle.js +379 -346
- package/lib/rules/comma-spacing.js +193 -195
- package/lib/rules/comma-style.js +375 -316
- package/lib/rules/complexity.js +173 -169
- package/lib/rules/computed-property-spacing.js +236 -211
- package/lib/rules/consistent-return.js +181 -170
- package/lib/rules/consistent-this.js +167 -147
- package/lib/rules/constructor-super.js +412 -404
- package/lib/rules/curly.js +407 -332
- package/lib/rules/default-case-last.js +38 -31
- package/lib/rules/default-case.js +89 -85
- package/lib/rules/default-param-last.js +69 -54
- package/lib/rules/dot-location.js +122 -110
- package/lib/rules/dot-notation.js +192 -156
- package/lib/rules/eol-last.js +122 -120
- package/lib/rules/eqeqeq.js +168 -155
- package/lib/rules/for-direction.js +146 -121
- package/lib/rules/func-call-spacing.js +261 -231
- package/lib/rules/func-name-matching.js +293 -209
- package/lib/rules/func-names.js +165 -164
- package/lib/rules/func-style.js +159 -127
- package/lib/rules/function-call-argument-newline.js +152 -129
- package/lib/rules/function-paren-newline.js +349 -291
- package/lib/rules/generator-star-spacing.js +229 -210
- package/lib/rules/getter-return.js +208 -172
- package/lib/rules/global-require.js +85 -74
- package/lib/rules/grouped-accessor-pairs.js +170 -150
- package/lib/rules/guard-for-in.js +72 -63
- package/lib/rules/handle-callback-err.js +108 -103
- package/lib/rules/id-blacklist.js +182 -199
- package/lib/rules/id-denylist.js +168 -187
- package/lib/rules/id-length.js +197 -171
- package/lib/rules/id-match.js +344 -289
- package/lib/rules/implicit-arrow-linebreak.js +102 -79
- package/lib/rules/indent-legacy.js +1344 -1118
- package/lib/rules/indent.js +2272 -1759
- package/lib/rules/index.js +317 -292
- package/lib/rules/init-declarations.js +137 -107
- package/lib/rules/jsx-quotes.js +94 -82
- package/lib/rules/key-spacing.js +750 -633
- package/lib/rules/keyword-spacing.js +648 -605
- package/lib/rules/line-comment-position.js +142 -128
- package/lib/rules/linebreak-style.js +107 -106
- package/lib/rules/lines-around-comment.js +540 -448
- package/lib/rules/lines-around-directive.js +233 -203
- package/lib/rules/lines-between-class-members.js +305 -234
- package/lib/rules/logical-assignment-operators.js +582 -399
- package/lib/rules/max-classes-per-file.js +69 -68
- package/lib/rules/max-depth.js +146 -143
- package/lib/rules/max-len.js +473 -434
- package/lib/rules/max-lines-per-function.js +201 -176
- package/lib/rules/max-lines.js +158 -162
- package/lib/rules/max-nested-callbacks.js +102 -104
- package/lib/rules/max-params.js +78 -76
- package/lib/rules/max-statements-per-line.js +205 -198
- package/lib/rules/max-statements.js +168 -164
- package/lib/rules/multiline-comment-style.js +637 -479
- package/lib/rules/multiline-ternary.js +241 -176
- package/lib/rules/new-cap.js +233 -213
- package/lib/rules/new-parens.js +88 -79
- package/lib/rules/newline-after-var.js +287 -250
- package/lib/rules/newline-before-return.js +229 -222
- package/lib/rules/newline-per-chained-call.js +142 -127
- package/lib/rules/no-alert.js +90 -79
- package/lib/rules/no-array-constructor.js +125 -113
- package/lib/rules/no-async-promise-executor.js +30 -24
- package/lib/rules/no-await-in-loop.js +69 -71
- package/lib/rules/no-bitwise.js +124 -100
- package/lib/rules/no-buffer-constructor.js +55 -47
- package/lib/rules/no-caller.js +39 -33
- package/lib/rules/no-case-declarations.js +61 -57
- package/lib/rules/no-catch-shadow.js +76 -73
- package/lib/rules/no-class-assign.js +51 -48
- package/lib/rules/no-compare-neg-zero.js +62 -48
- package/lib/rules/no-cond-assign.js +148 -132
- package/lib/rules/no-confusing-arrow.js +98 -81
- package/lib/rules/no-console.js +202 -199
- package/lib/rules/no-const-assign.js +47 -41
- package/lib/rules/no-constant-binary-expression.js +500 -405
- package/lib/rules/no-constant-condition.js +158 -143
- package/lib/rules/no-constructor-return.js +49 -49
- package/lib/rules/no-continue.js +25 -27
- package/lib/rules/no-control-regex.js +125 -121
- package/lib/rules/no-debugger.js +28 -30
- package/lib/rules/no-delete-var.js +29 -29
- package/lib/rules/no-div-regex.js +47 -41
- package/lib/rules/no-dupe-args.js +68 -69
- package/lib/rules/no-dupe-class-members.js +102 -89
- package/lib/rules/no-dupe-else-if.js +100 -77
- package/lib/rules/no-dupe-keys.js +133 -110
- package/lib/rules/no-duplicate-case.js +50 -43
- package/lib/rules/no-duplicate-imports.js +179 -176
- package/lib/rules/no-else-return.js +430 -385
- package/lib/rules/no-empty-character-class.js +57 -50
- package/lib/rules/no-empty-function.js +127 -128
- package/lib/rules/no-empty-pattern.js +63 -58
- package/lib/rules/no-empty-static-block.js +37 -35
- package/lib/rules/no-empty.js +98 -86
- package/lib/rules/no-eq-null.js +37 -32
- package/lib/rules/no-eval.js +256 -250
- package/lib/rules/no-ex-assign.js +42 -39
- package/lib/rules/no-extend-native.js +161 -159
- package/lib/rules/no-extra-bind.js +201 -190
- package/lib/rules/no-extra-boolean-cast.js +398 -348
- package/lib/rules/no-extra-label.js +150 -131
- package/lib/rules/no-extra-parens.js +1654 -1325
- package/lib/rules/no-extra-semi.js +146 -144
- package/lib/rules/no-fallthrough.js +199 -157
- package/lib/rules/no-floating-decimal.js +74 -66
- package/lib/rules/no-func-assign.js +54 -55
- package/lib/rules/no-global-assign.js +78 -73
- package/lib/rules/no-implicit-coercion.js +349 -293
- package/lib/rules/no-implicit-globals.js +158 -135
- package/lib/rules/no-implied-eval.js +140 -112
- package/lib/rules/no-import-assign.js +145 -159
- package/lib/rules/no-inline-comments.js +101 -95
- package/lib/rules/no-inner-declarations.js +115 -101
- package/lib/rules/no-invalid-regexp.js +222 -190
- package/lib/rules/no-invalid-this.js +123 -117
- package/lib/rules/no-irregular-whitespace.js +266 -252
- package/lib/rules/no-iterator.js +29 -33
- package/lib/rules/no-label-var.js +59 -62
- package/lib/rules/no-labels.js +138 -133
- package/lib/rules/no-lone-blocks.js +127 -123
- package/lib/rules/no-lonely-if.js +108 -77
- package/lib/rules/no-loop-func.js +238 -213
- package/lib/rules/no-loss-of-precision.js +218 -201
- package/lib/rules/no-magic-numbers.js +246 -218
- package/lib/rules/no-misleading-character-class.js +499 -446
- package/lib/rules/no-mixed-operators.js +188 -182
- package/lib/rules/no-mixed-requires.js +253 -240
- package/lib/rules/no-mixed-spaces-and-tabs.js +134 -121
- package/lib/rules/no-multi-assign.js +46 -44
- package/lib/rules/no-multi-spaces.js +163 -143
- package/lib/rules/no-multi-str.js +42 -41
- package/lib/rules/no-multiple-empty-lines.js +196 -158
- package/lib/rules/no-native-reassign.js +90 -85
- package/lib/rules/no-negated-condition.js +79 -75
- package/lib/rules/no-negated-in-lhs.js +45 -43
- package/lib/rules/no-nested-ternary.js +33 -32
- package/lib/rules/no-new-func.js +71 -62
- package/lib/rules/no-new-native-nonconstructor.js +43 -39
- package/lib/rules/no-new-object.js +48 -48
- package/lib/rules/no-new-require.js +48 -47
- package/lib/rules/no-new-symbol.js +52 -50
- package/lib/rules/no-new-wrappers.js +43 -41
- package/lib/rules/no-new.js +28 -29
- package/lib/rules/no-nonoctal-decimal-escape.js +141 -121
- package/lib/rules/no-obj-calls.js +66 -53
- package/lib/rules/no-object-constructor.js +104 -97
- package/lib/rules/no-octal-escape.js +40 -43
- package/lib/rules/no-octal.js +32 -32
- package/lib/rules/no-param-reassign.js +235 -217
- package/lib/rules/no-path-concat.js +66 -67
- package/lib/rules/no-plusplus.js +60 -61
- package/lib/rules/no-process-env.js +49 -48
- package/lib/rules/no-process-exit.js +54 -50
- package/lib/rules/no-promise-executor-return.js +214 -182
- package/lib/rules/no-proto.js +26 -29
- package/lib/rules/no-prototype-builtins.js +146 -124
- package/lib/rules/no-redeclare.js +154 -152
- package/lib/rules/no-regex-spaces.js +183 -161
- package/lib/rules/no-restricted-exports.js +208 -185
- package/lib/rules/no-restricted-globals.js +111 -112
- package/lib/rules/no-restricted-imports.js +657 -537
- package/lib/rules/no-restricted-modules.js +222 -202
- package/lib/rules/no-restricted-properties.js +181 -153
- package/lib/rules/no-restricted-syntax.js +56 -52
- package/lib/rules/no-return-assign.js +55 -50
- package/lib/rules/no-return-await.js +148 -124
- package/lib/rules/no-script-url.js +52 -45
- package/lib/rules/no-self-assign.js +148 -146
- package/lib/rules/no-self-compare.js +63 -46
- package/lib/rules/no-sequences.js +135 -116
- package/lib/rules/no-setter-return.js +185 -152
- package/lib/rules/no-shadow-restricted-names.js +61 -46
- package/lib/rules/no-shadow.js +342 -316
- package/lib/rules/no-spaced-func.js +82 -77
- package/lib/rules/no-sparse-arrays.js +54 -59
- package/lib/rules/no-sync.js +61 -60
- package/lib/rules/no-tabs.js +83 -72
- package/lib/rules/no-template-curly-in-string.js +33 -32
- package/lib/rules/no-ternary.js +25 -29
- package/lib/rules/no-this-before-super.js +321 -319
- package/lib/rules/no-throw-literal.js +31 -36
- package/lib/rules/no-trailing-spaces.js +199 -191
- package/lib/rules/no-undef-init.js +76 -61
- package/lib/rules/no-undef.js +51 -48
- package/lib/rules/no-undefined.js +73 -75
- package/lib/rules/no-underscore-dangle.js +370 -327
- package/lib/rules/no-unexpected-multiline.js +112 -102
- package/lib/rules/no-unmodified-loop-condition.js +254 -254
- package/lib/rules/no-unneeded-ternary.js +212 -147
- package/lib/rules/no-unreachable-loop.js +145 -142
- package/lib/rules/no-unreachable.js +255 -248
- package/lib/rules/no-unsafe-finally.js +93 -85
- package/lib/rules/no-unsafe-negation.js +105 -83
- package/lib/rules/no-unsafe-optional-chaining.js +192 -178
- package/lib/rules/no-unused-expressions.js +178 -162
- package/lib/rules/no-unused-labels.js +139 -124
- package/lib/rules/no-unused-private-class-members.js +206 -182
- package/lib/rules/no-unused-vars.js +1669 -1449
- package/lib/rules/no-use-before-define.js +229 -231
- package/lib/rules/no-useless-assignment.js +590 -511
- package/lib/rules/no-useless-backreference.js +212 -193
- package/lib/rules/no-useless-call.js +58 -53
- package/lib/rules/no-useless-catch.js +40 -40
- package/lib/rules/no-useless-computed-key.js +144 -115
- package/lib/rules/no-useless-concat.js +65 -60
- package/lib/rules/no-useless-constructor.js +158 -111
- package/lib/rules/no-useless-escape.js +342 -291
- package/lib/rules/no-useless-rename.js +183 -156
- package/lib/rules/no-useless-return.js +344 -312
- package/lib/rules/no-var.js +233 -212
- package/lib/rules/no-void.js +50 -48
- package/lib/rules/no-warning-comments.js +191 -186
- package/lib/rules/no-whitespace-before-property.js +131 -115
- package/lib/rules/no-with.js +24 -26
- package/lib/rules/nonblock-statement-body-position.js +149 -130
- package/lib/rules/object-curly-newline.js +306 -265
- package/lib/rules/object-curly-spacing.js +360 -314
- package/lib/rules/object-property-newline.js +137 -106
- package/lib/rules/object-shorthand.js +607 -502
- package/lib/rules/one-var-declaration-per-line.js +104 -100
- package/lib/rules/one-var.js +653 -537
- package/lib/rules/operator-assignment.js +219 -161
- package/lib/rules/operator-linebreak.js +295 -251
- package/lib/rules/padded-blocks.js +346 -308
- package/lib/rules/padding-line-between-statements.js +443 -439
- package/lib/rules/prefer-arrow-callback.js +362 -313
- package/lib/rules/prefer-const.js +418 -377
- package/lib/rules/prefer-destructuring.js +301 -279
- package/lib/rules/prefer-exponentiation-operator.js +176 -133
- package/lib/rules/prefer-named-capture-group.js +153 -140
- package/lib/rules/prefer-numeric-literals.js +121 -113
- package/lib/rules/prefer-object-has-own.js +116 -82
- package/lib/rules/prefer-object-spread.js +213 -193
- package/lib/rules/prefer-promise-reject-errors.js +140 -122
- package/lib/rules/prefer-reflect.js +127 -107
- package/lib/rules/prefer-regex-literals.js +578 -466
- package/lib/rules/prefer-rest-params.js +79 -80
- package/lib/rules/prefer-spread.js +47 -44
- package/lib/rules/prefer-template.js +266 -195
- package/lib/rules/quote-props.js +373 -307
- package/lib/rules/quotes.js +374 -326
- package/lib/rules/radix.js +152 -136
- package/lib/rules/require-atomic-updates.js +316 -285
- package/lib/rules/require-await.js +144 -116
- package/lib/rules/require-unicode-regexp.js +282 -177
- package/lib/rules/require-yield.js +53 -54
- package/lib/rules/rest-spread-spacing.js +128 -116
- package/lib/rules/semi-spacing.js +281 -250
- package/lib/rules/semi-style.js +176 -134
- package/lib/rules/semi.js +456 -436
- package/lib/rules/sort-imports.js +306 -233
- package/lib/rules/sort-keys.js +219 -188
- package/lib/rules/sort-vars.js +127 -93
- package/lib/rules/space-before-blocks.js +199 -189
- package/lib/rules/space-before-function-paren.js +186 -166
- package/lib/rules/space-in-parens.js +359 -288
- package/lib/rules/space-infix-ops.js +237 -201
- package/lib/rules/space-unary-ops.js +356 -298
- package/lib/rules/spaced-comment.js +363 -319
- package/lib/rules/strict.js +265 -230
- package/lib/rules/switch-colon-spacing.js +130 -122
- package/lib/rules/symbol-description.js +45 -48
- package/lib/rules/template-curly-spacing.js +148 -142
- package/lib/rules/template-tag-spacing.js +98 -88
- package/lib/rules/unicode-bom.js +54 -56
- package/lib/rules/use-isnan.js +237 -206
- package/lib/rules/utils/ast-utils.js +2039 -1860
- package/lib/rules/utils/char-source.js +162 -155
- package/lib/rules/utils/fix-tracker.js +83 -80
- package/lib/rules/utils/keywords.js +59 -59
- package/lib/rules/utils/lazy-loading-rule-map.js +79 -76
- package/lib/rules/utils/regular-expressions.js +32 -24
- package/lib/rules/utils/unicode/index.js +4 -4
- package/lib/rules/utils/unicode/is-combining-character.js +1 -1
- package/lib/rules/utils/unicode/is-emoji-modifier.js +1 -1
- package/lib/rules/utils/unicode/is-regional-indicator-symbol.js +1 -1
- package/lib/rules/utils/unicode/is-surrogate-pair.js +1 -1
- package/lib/rules/valid-typeof.js +153 -111
- package/lib/rules/vars-on-top.js +152 -145
- package/lib/rules/wrap-iife.js +204 -191
- package/lib/rules/wrap-regex.js +70 -58
- package/lib/rules/yield-star-spacing.js +145 -134
- package/lib/rules/yoda.js +283 -272
- package/lib/services/parser-service.js +35 -35
- package/lib/services/processor-service.js +66 -73
- package/lib/services/suppressions-service.js +289 -0
- package/lib/shared/ajv.js +14 -14
- package/lib/shared/assert.js +3 -4
- package/lib/shared/ast-utils.js +7 -6
- package/lib/shared/deep-merge-arrays.js +24 -22
- package/lib/shared/directives.js +3 -2
- package/lib/shared/flags.js +50 -17
- package/lib/shared/logging.js +24 -25
- package/lib/shared/option-utils.js +43 -36
- package/lib/shared/runtime-info.js +136 -127
- package/lib/shared/serialization.js +27 -27
- package/lib/shared/severity.js +22 -22
- package/lib/shared/stats.js +5 -5
- package/lib/shared/string-utils.js +16 -16
- package/lib/shared/text-table.js +28 -27
- package/lib/shared/traverser.js +153 -146
- package/lib/shared/types.js +4 -27
- package/lib/types/index.d.ts +2010 -1559
- package/lib/types/rules.d.ts +5253 -5140
- package/lib/types/use-at-your-own-risk.d.ts +32 -30
- package/lib/unsupported-api.js +5 -5
- package/messages/all-files-ignored.js +3 -3
- package/messages/all-matched-files-ignored.js +3 -3
- package/messages/config-file-missing.js +2 -2
- package/messages/config-plugin-missing.js +3 -3
- package/messages/config-serialize-function.js +9 -7
- package/messages/eslintrc-incompat.js +13 -15
- package/messages/eslintrc-plugins.js +3 -4
- package/messages/extend-config-missing.js +3 -3
- package/messages/failed-to-read-json.js +3 -3
- package/messages/file-not-found.js +3 -3
- package/messages/invalid-rule-options.js +2 -2
- package/messages/invalid-rule-severity.js +2 -2
- package/messages/no-config-found.js +3 -3
- package/messages/plugin-conflict.js +8 -8
- package/messages/plugin-invalid.js +3 -3
- package/messages/plugin-missing.js +3 -3
- package/messages/print-config-with-directory-path.js +2 -2
- package/messages/shared.js +6 -1
- package/messages/whitespace-found.js +3 -3
- package/package.json +14 -20
@@ -10,7 +10,7 @@
|
|
10
10
|
//------------------------------------------------------------------------------
|
11
11
|
|
12
12
|
const CodePathSegment = require("./code-path-segment"),
|
13
|
-
|
13
|
+
ForkContext = require("./fork-context");
|
14
14
|
|
15
15
|
//-----------------------------------------------------------------------------
|
16
16
|
// Contexts
|
@@ -35,68 +35,63 @@ const CodePathSegment = require("./code-path-segment"),
|
|
35
35
|
* that `break` without a label is invalid.
|
36
36
|
*/
|
37
37
|
class BreakContext {
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
this.brokenForkContext = ForkContext.newEmpty(forkContext);
|
73
|
-
}
|
38
|
+
/**
|
39
|
+
* Creates a new instance.
|
40
|
+
* @param {BreakContext} upperContext The previous `BreakContext`.
|
41
|
+
* @param {boolean} breakable Indicates if we are inside a statement where
|
42
|
+
* `break` without a label will exit the statement.
|
43
|
+
* @param {string|null} label The label for the statement.
|
44
|
+
* @param {ForkContext} forkContext The current fork context.
|
45
|
+
*/
|
46
|
+
constructor(upperContext, breakable, label, forkContext) {
|
47
|
+
/**
|
48
|
+
* The previous `BreakContext`
|
49
|
+
* @type {BreakContext}
|
50
|
+
*/
|
51
|
+
this.upper = upperContext;
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Indicates if we are inside a statement where `break` without a label
|
55
|
+
* will exit the statement.
|
56
|
+
* @type {boolean}
|
57
|
+
*/
|
58
|
+
this.breakable = breakable;
|
59
|
+
|
60
|
+
/**
|
61
|
+
* The label associated with the statement.
|
62
|
+
* @type {string|null}
|
63
|
+
*/
|
64
|
+
this.label = label;
|
65
|
+
|
66
|
+
/**
|
67
|
+
* The fork context for the `break`.
|
68
|
+
* @type {ForkContext}
|
69
|
+
*/
|
70
|
+
this.brokenForkContext = ForkContext.newEmpty(forkContext);
|
71
|
+
}
|
74
72
|
}
|
75
73
|
|
76
74
|
/**
|
77
75
|
* Represents the context for `ChainExpression` nodes.
|
78
76
|
*/
|
79
77
|
class ChainContext {
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
this.choiceContextCount = 0;
|
98
|
-
|
99
|
-
}
|
78
|
+
/**
|
79
|
+
* Creates a new instance.
|
80
|
+
* @param {ChainContext} upperContext The previous `ChainContext`.
|
81
|
+
*/
|
82
|
+
constructor(upperContext) {
|
83
|
+
/**
|
84
|
+
* The previous `ChainContext`
|
85
|
+
* @type {ChainContext}
|
86
|
+
*/
|
87
|
+
this.upper = upperContext;
|
88
|
+
|
89
|
+
/**
|
90
|
+
* The number of choice contexts inside of the `ChainContext`.
|
91
|
+
* @type {number}
|
92
|
+
*/
|
93
|
+
this.choiceContextCount = 0;
|
94
|
+
}
|
100
95
|
}
|
101
96
|
|
102
97
|
/**
|
@@ -124,249 +119,241 @@ class ChainContext {
|
|
124
119
|
* we fork to the right expression (tracked by `nullishForkContext`).
|
125
120
|
*/
|
126
121
|
class ChoiceContext {
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
this.processed = false;
|
184
|
-
}
|
185
|
-
|
122
|
+
/**
|
123
|
+
* Creates a new instance.
|
124
|
+
* @param {ChoiceContext} upperContext The previous `ChoiceContext`.
|
125
|
+
* @param {string} kind The kind of choice. If it's a logical or assignment expression, this
|
126
|
+
* is `"&&"` or `"||"` or `"??"`; if it's an `if` statement or
|
127
|
+
* conditional expression, this is `"test"`; otherwise, this is `"loop"`.
|
128
|
+
* @param {boolean} isForkingAsResult Indicates if the result of the choice
|
129
|
+
* creates a fork.
|
130
|
+
* @param {ForkContext} forkContext The containing `ForkContext`.
|
131
|
+
*/
|
132
|
+
constructor(upperContext, kind, isForkingAsResult, forkContext) {
|
133
|
+
/**
|
134
|
+
* The previous `ChoiceContext`
|
135
|
+
* @type {ChoiceContext}
|
136
|
+
*/
|
137
|
+
this.upper = upperContext;
|
138
|
+
|
139
|
+
/**
|
140
|
+
* The kind of choice. If it's a logical or assignment expression, this
|
141
|
+
* is `"&&"` or `"||"` or `"??"`; if it's an `if` statement or
|
142
|
+
* conditional expression, this is `"test"`; otherwise, this is `"loop"`.
|
143
|
+
* @type {string}
|
144
|
+
*/
|
145
|
+
this.kind = kind;
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Indicates if the result of the choice forks the code path.
|
149
|
+
* @type {boolean}
|
150
|
+
*/
|
151
|
+
this.isForkingAsResult = isForkingAsResult;
|
152
|
+
|
153
|
+
/**
|
154
|
+
* The fork context for the `true` path of the choice.
|
155
|
+
* @type {ForkContext}
|
156
|
+
*/
|
157
|
+
this.trueForkContext = ForkContext.newEmpty(forkContext);
|
158
|
+
|
159
|
+
/**
|
160
|
+
* The fork context for the `false` path of the choice.
|
161
|
+
* @type {ForkContext}
|
162
|
+
*/
|
163
|
+
this.falseForkContext = ForkContext.newEmpty(forkContext);
|
164
|
+
|
165
|
+
/**
|
166
|
+
* The fork context for when the choice result is `null` or `undefined`.
|
167
|
+
* @type {ForkContext}
|
168
|
+
*/
|
169
|
+
this.nullishForkContext = ForkContext.newEmpty(forkContext);
|
170
|
+
|
171
|
+
/**
|
172
|
+
* Indicates if any of `trueForkContext`, `falseForkContext`, or
|
173
|
+
* `nullishForkContext` have been updated with segments from a child context.
|
174
|
+
* @type {boolean}
|
175
|
+
*/
|
176
|
+
this.processed = false;
|
177
|
+
}
|
186
178
|
}
|
187
179
|
|
188
180
|
/**
|
189
181
|
* Base class for all loop contexts.
|
190
182
|
*/
|
191
183
|
class LoopContextBase {
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
this.brokenForkContext = breakContext.brokenForkContext;
|
225
|
-
}
|
184
|
+
/**
|
185
|
+
* Creates a new instance.
|
186
|
+
* @param {LoopContext|null} upperContext The previous `LoopContext`.
|
187
|
+
* @param {string} type The AST node's `type` for the loop.
|
188
|
+
* @param {string|null} label The label for the loop from an enclosing `LabeledStatement`.
|
189
|
+
* @param {BreakContext} breakContext The context for breaking the loop.
|
190
|
+
*/
|
191
|
+
constructor(upperContext, type, label, breakContext) {
|
192
|
+
/**
|
193
|
+
* The previous `LoopContext`.
|
194
|
+
* @type {LoopContext}
|
195
|
+
*/
|
196
|
+
this.upper = upperContext;
|
197
|
+
|
198
|
+
/**
|
199
|
+
* The AST node's `type` for the loop.
|
200
|
+
* @type {string}
|
201
|
+
*/
|
202
|
+
this.type = type;
|
203
|
+
|
204
|
+
/**
|
205
|
+
* The label for the loop from an enclosing `LabeledStatement`.
|
206
|
+
* @type {string|null}
|
207
|
+
*/
|
208
|
+
this.label = label;
|
209
|
+
|
210
|
+
/**
|
211
|
+
* The fork context for when `break` is encountered.
|
212
|
+
* @type {ForkContext}
|
213
|
+
*/
|
214
|
+
this.brokenForkContext = breakContext.brokenForkContext;
|
215
|
+
}
|
226
216
|
}
|
227
217
|
|
228
218
|
/**
|
229
219
|
* Represents the context for a `while` loop.
|
230
220
|
*/
|
231
221
|
class WhileLoopContext extends LoopContextBase {
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
}
|
222
|
+
/**
|
223
|
+
* Creates a new instance.
|
224
|
+
* @param {LoopContext|null} upperContext The previous `LoopContext`.
|
225
|
+
* @param {string|null} label The label for the loop from an enclosing `LabeledStatement`.
|
226
|
+
* @param {BreakContext} breakContext The context for breaking the loop.
|
227
|
+
*/
|
228
|
+
constructor(upperContext, label, breakContext) {
|
229
|
+
super(upperContext, "WhileStatement", label, breakContext);
|
230
|
+
|
231
|
+
/**
|
232
|
+
* The hardcoded literal boolean test condition for
|
233
|
+
* the loop. Used to catch infinite or skipped loops.
|
234
|
+
* @type {boolean|undefined}
|
235
|
+
*/
|
236
|
+
this.test = void 0;
|
237
|
+
|
238
|
+
/**
|
239
|
+
* The segments representing the test condition where `continue` will
|
240
|
+
* jump to. The test condition will typically have just one segment but
|
241
|
+
* it's possible for there to be more than one.
|
242
|
+
* @type {Array<CodePathSegment>|null}
|
243
|
+
*/
|
244
|
+
this.continueDestSegments = null;
|
245
|
+
}
|
257
246
|
}
|
258
247
|
|
259
248
|
/**
|
260
249
|
* Represents the context for a `do-while` loop.
|
261
250
|
*/
|
262
251
|
class DoWhileLoopContext extends LoopContextBase {
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
}
|
252
|
+
/**
|
253
|
+
* Creates a new instance.
|
254
|
+
* @param {LoopContext|null} upperContext The previous `LoopContext`.
|
255
|
+
* @param {string|null} label The label for the loop from an enclosing `LabeledStatement`.
|
256
|
+
* @param {BreakContext} breakContext The context for breaking the loop.
|
257
|
+
* @param {ForkContext} forkContext The enclosing fork context.
|
258
|
+
*/
|
259
|
+
constructor(upperContext, label, breakContext, forkContext) {
|
260
|
+
super(upperContext, "DoWhileStatement", label, breakContext);
|
261
|
+
|
262
|
+
/**
|
263
|
+
* The hardcoded literal boolean test condition for
|
264
|
+
* the loop. Used to catch infinite or skipped loops.
|
265
|
+
* @type {boolean|undefined}
|
266
|
+
*/
|
267
|
+
this.test = void 0;
|
268
|
+
|
269
|
+
/**
|
270
|
+
* The segments at the start of the loop body. This is the only loop
|
271
|
+
* where the test comes at the end, so the first iteration always
|
272
|
+
* happens and we need a reference to the first statements.
|
273
|
+
* @type {Array<CodePathSegment>|null}
|
274
|
+
*/
|
275
|
+
this.entrySegments = null;
|
276
|
+
|
277
|
+
/**
|
278
|
+
* The fork context to follow when a `continue` is found.
|
279
|
+
* @type {ForkContext}
|
280
|
+
*/
|
281
|
+
this.continueForkContext = ForkContext.newEmpty(forkContext);
|
282
|
+
}
|
295
283
|
}
|
296
284
|
|
297
285
|
/**
|
298
286
|
* Represents the context for a `for` loop.
|
299
287
|
*/
|
300
288
|
class ForLoopContext extends LoopContextBase {
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
}
|
289
|
+
/**
|
290
|
+
* Creates a new instance.
|
291
|
+
* @param {LoopContext|null} upperContext The previous `LoopContext`.
|
292
|
+
* @param {string|null} label The label for the loop from an enclosing `LabeledStatement`.
|
293
|
+
* @param {BreakContext} breakContext The context for breaking the loop.
|
294
|
+
*/
|
295
|
+
constructor(upperContext, label, breakContext) {
|
296
|
+
super(upperContext, "ForStatement", label, breakContext);
|
297
|
+
|
298
|
+
/**
|
299
|
+
* The hardcoded literal boolean test condition for
|
300
|
+
* the loop. Used to catch infinite or skipped loops.
|
301
|
+
* @type {boolean|undefined}
|
302
|
+
*/
|
303
|
+
this.test = void 0;
|
304
|
+
|
305
|
+
/**
|
306
|
+
* The end of the init expression. This may change during the lifetime
|
307
|
+
* of the instance as we traverse the loop because some loops don't have
|
308
|
+
* an init expression.
|
309
|
+
* @type {Array<CodePathSegment>|null}
|
310
|
+
*/
|
311
|
+
this.endOfInitSegments = null;
|
312
|
+
|
313
|
+
/**
|
314
|
+
* The start of the test expression. This may change during the lifetime
|
315
|
+
* of the instance as we traverse the loop because some loops don't have
|
316
|
+
* a test expression.
|
317
|
+
* @type {Array<CodePathSegment>|null}
|
318
|
+
*/
|
319
|
+
this.testSegments = null;
|
320
|
+
|
321
|
+
/**
|
322
|
+
* The end of the test expression. This may change during the lifetime
|
323
|
+
* of the instance as we traverse the loop because some loops don't have
|
324
|
+
* a test expression.
|
325
|
+
* @type {Array<CodePathSegment>|null}
|
326
|
+
*/
|
327
|
+
this.endOfTestSegments = null;
|
328
|
+
|
329
|
+
/**
|
330
|
+
* The start of the update expression. This may change during the lifetime
|
331
|
+
* of the instance as we traverse the loop because some loops don't have
|
332
|
+
* an update expression.
|
333
|
+
* @type {Array<CodePathSegment>|null}
|
334
|
+
*/
|
335
|
+
this.updateSegments = null;
|
336
|
+
|
337
|
+
/**
|
338
|
+
* The end of the update expression. This may change during the lifetime
|
339
|
+
* of the instance as we traverse the loop because some loops don't have
|
340
|
+
* an update expression.
|
341
|
+
* @type {Array<CodePathSegment>|null}
|
342
|
+
*/
|
343
|
+
this.endOfUpdateSegments = null;
|
344
|
+
|
345
|
+
/**
|
346
|
+
* The segments representing the test condition where `continue` will
|
347
|
+
* jump to. The test condition will typically have just one segment but
|
348
|
+
* it's possible for there to be more than one. This may change during the
|
349
|
+
* lifetime of the instance as we traverse the loop because some loops
|
350
|
+
* don't have an update expression. When there is an update expression, this
|
351
|
+
* will end up pointing to that expression; otherwise it will end up pointing
|
352
|
+
* to the test expression.
|
353
|
+
* @type {Array<CodePathSegment>|null}
|
354
|
+
*/
|
355
|
+
this.continueDestSegments = null;
|
356
|
+
}
|
370
357
|
}
|
371
358
|
|
372
359
|
/**
|
@@ -379,114 +366,112 @@ class ForLoopContext extends LoopContextBase {
|
|
379
366
|
* example, in `for (var x in y)`, the right is `y`.
|
380
367
|
*/
|
381
368
|
class ForInLoopContext extends LoopContextBase {
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
}
|
369
|
+
/**
|
370
|
+
* Creates a new instance.
|
371
|
+
* @param {LoopContext|null} upperContext The previous `LoopContext`.
|
372
|
+
* @param {string|null} label The label for the loop from an enclosing `LabeledStatement`.
|
373
|
+
* @param {BreakContext} breakContext The context for breaking the loop.
|
374
|
+
*/
|
375
|
+
constructor(upperContext, label, breakContext) {
|
376
|
+
super(upperContext, "ForInStatement", label, breakContext);
|
377
|
+
|
378
|
+
/**
|
379
|
+
* The segments that came immediately before the start of the loop.
|
380
|
+
* This allows you to traverse backwards out of the loop into the
|
381
|
+
* surrounding code. This is necessary to evaluate the right expression
|
382
|
+
* correctly, as it must be evaluated in the same way as the left
|
383
|
+
* expression, but the pointer to these segments would otherwise be
|
384
|
+
* lost if not stored on the instance. Once the right expression has
|
385
|
+
* been evaluated, this property is no longer used.
|
386
|
+
* @type {Array<CodePathSegment>|null}
|
387
|
+
*/
|
388
|
+
this.prevSegments = null;
|
389
|
+
|
390
|
+
/**
|
391
|
+
* Segments representing the start of everything to the left of the
|
392
|
+
* `in` keyword. This can be used to move forward towards
|
393
|
+
* `endOfLeftSegments`. `leftSegments` and `endOfLeftSegments` are
|
394
|
+
* effectively the head and tail of a doubly-linked list.
|
395
|
+
* @type {Array<CodePathSegment>|null}
|
396
|
+
*/
|
397
|
+
this.leftSegments = null;
|
398
|
+
|
399
|
+
/**
|
400
|
+
* Segments representing the end of everything to the left of the
|
401
|
+
* `in` keyword. This can be used to move backward towards `leftSegments`.
|
402
|
+
* `leftSegments` and `endOfLeftSegments` are effectively the head
|
403
|
+
* and tail of a doubly-linked list.
|
404
|
+
* @type {Array<CodePathSegment>|null}
|
405
|
+
*/
|
406
|
+
this.endOfLeftSegments = null;
|
407
|
+
|
408
|
+
/**
|
409
|
+
* The segments representing the left expression where `continue` will
|
410
|
+
* jump to. In `for-in` loops, `continue` must always re-execute the
|
411
|
+
* left expression each time through the loop. This contains the same
|
412
|
+
* segments as `leftSegments`, but is duplicated here so each loop
|
413
|
+
* context has the same property pointing to where `continue` should
|
414
|
+
* end up.
|
415
|
+
* @type {Array<CodePathSegment>|null}
|
416
|
+
*/
|
417
|
+
this.continueDestSegments = null;
|
418
|
+
}
|
433
419
|
}
|
434
420
|
|
435
421
|
/**
|
436
422
|
* Represents the context for a `for-of` loop.
|
437
423
|
*/
|
438
424
|
class ForOfLoopContext extends LoopContextBase {
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
}
|
425
|
+
/**
|
426
|
+
* Creates a new instance.
|
427
|
+
* @param {LoopContext|null} upperContext The previous `LoopContext`.
|
428
|
+
* @param {string|null} label The label for the loop from an enclosing `LabeledStatement`.
|
429
|
+
* @param {BreakContext} breakContext The context for breaking the loop.
|
430
|
+
*/
|
431
|
+
constructor(upperContext, label, breakContext) {
|
432
|
+
super(upperContext, "ForOfStatement", label, breakContext);
|
433
|
+
|
434
|
+
/**
|
435
|
+
* The segments that came immediately before the start of the loop.
|
436
|
+
* This allows you to traverse backwards out of the loop into the
|
437
|
+
* surrounding code. This is necessary to evaluate the right expression
|
438
|
+
* correctly, as it must be evaluated in the same way as the left
|
439
|
+
* expression, but the pointer to these segments would otherwise be
|
440
|
+
* lost if not stored on the instance. Once the right expression has
|
441
|
+
* been evaluated, this property is no longer used.
|
442
|
+
* @type {Array<CodePathSegment>|null}
|
443
|
+
*/
|
444
|
+
this.prevSegments = null;
|
445
|
+
|
446
|
+
/**
|
447
|
+
* Segments representing the start of everything to the left of the
|
448
|
+
* `of` keyword. This can be used to move forward towards
|
449
|
+
* `endOfLeftSegments`. `leftSegments` and `endOfLeftSegments` are
|
450
|
+
* effectively the head and tail of a doubly-linked list.
|
451
|
+
* @type {Array<CodePathSegment>|null}
|
452
|
+
*/
|
453
|
+
this.leftSegments = null;
|
454
|
+
|
455
|
+
/**
|
456
|
+
* Segments representing the end of everything to the left of the
|
457
|
+
* `of` keyword. This can be used to move backward towards `leftSegments`.
|
458
|
+
* `leftSegments` and `endOfLeftSegments` are effectively the head
|
459
|
+
* and tail of a doubly-linked list.
|
460
|
+
* @type {Array<CodePathSegment>|null}
|
461
|
+
*/
|
462
|
+
this.endOfLeftSegments = null;
|
463
|
+
|
464
|
+
/**
|
465
|
+
* The segments representing the left expression where `continue` will
|
466
|
+
* jump to. In `for-in` loops, `continue` must always re-execute the
|
467
|
+
* left expression each time through the loop. This contains the same
|
468
|
+
* segments as `leftSegments`, but is duplicated here so each loop
|
469
|
+
* context has the same property pointing to where `continue` should
|
470
|
+
* end up.
|
471
|
+
* @type {Array<CodePathSegment>|null}
|
472
|
+
*/
|
473
|
+
this.continueDestSegments = null;
|
474
|
+
}
|
490
475
|
}
|
491
476
|
|
492
477
|
/**
|
@@ -498,127 +483,123 @@ class ForOfLoopContext extends LoopContextBase {
|
|
498
483
|
* Represents the context for a `switch` statement.
|
499
484
|
*/
|
500
485
|
class SwitchContext {
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
this.forkCount = 0;
|
552
|
-
}
|
486
|
+
/**
|
487
|
+
* Creates a new instance.
|
488
|
+
* @param {SwitchContext} upperContext The previous context.
|
489
|
+
* @param {boolean} hasCase Indicates if there is at least one `case` statement.
|
490
|
+
* `default` doesn't count.
|
491
|
+
*/
|
492
|
+
constructor(upperContext, hasCase) {
|
493
|
+
/**
|
494
|
+
* The previous context.
|
495
|
+
* @type {SwitchContext}
|
496
|
+
*/
|
497
|
+
this.upper = upperContext;
|
498
|
+
|
499
|
+
/**
|
500
|
+
* Indicates if there is at least one `case` statement. `default` doesn't count.
|
501
|
+
* @type {boolean}
|
502
|
+
*/
|
503
|
+
this.hasCase = hasCase;
|
504
|
+
|
505
|
+
/**
|
506
|
+
* The `default` keyword.
|
507
|
+
* @type {Array<CodePathSegment>|null}
|
508
|
+
*/
|
509
|
+
this.defaultSegments = null;
|
510
|
+
|
511
|
+
/**
|
512
|
+
* The default case body starting segments.
|
513
|
+
* @type {Array<CodePathSegment>|null}
|
514
|
+
*/
|
515
|
+
this.defaultBodySegments = null;
|
516
|
+
|
517
|
+
/**
|
518
|
+
* Indicates if a `default` case and is empty exists.
|
519
|
+
* @type {boolean}
|
520
|
+
*/
|
521
|
+
this.foundEmptyDefault = false;
|
522
|
+
|
523
|
+
/**
|
524
|
+
* Indicates that a `default` exists and is the last case.
|
525
|
+
* @type {boolean}
|
526
|
+
*/
|
527
|
+
this.lastIsDefault = false;
|
528
|
+
|
529
|
+
/**
|
530
|
+
* The number of fork contexts created. This is equivalent to the
|
531
|
+
* number of `case` statements plus a `default` statement (if present).
|
532
|
+
* @type {number}
|
533
|
+
*/
|
534
|
+
this.forkCount = 0;
|
535
|
+
}
|
553
536
|
}
|
554
537
|
|
555
538
|
/**
|
556
539
|
* Represents the context for a `try` statement.
|
557
540
|
*/
|
558
541
|
class TryContext {
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
this.lastOfCatchIsReachable = false;
|
621
|
-
}
|
542
|
+
/**
|
543
|
+
* Creates a new instance.
|
544
|
+
* @param {TryContext} upperContext The previous context.
|
545
|
+
* @param {boolean} hasFinalizer Indicates if the `try` statement has a
|
546
|
+
* `finally` block.
|
547
|
+
* @param {ForkContext} forkContext The enclosing fork context.
|
548
|
+
*/
|
549
|
+
constructor(upperContext, hasFinalizer, forkContext) {
|
550
|
+
/**
|
551
|
+
* The previous context.
|
552
|
+
* @type {TryContext}
|
553
|
+
*/
|
554
|
+
this.upper = upperContext;
|
555
|
+
|
556
|
+
/**
|
557
|
+
* Indicates if the `try` statement has a `finally` block.
|
558
|
+
* @type {boolean}
|
559
|
+
*/
|
560
|
+
this.hasFinalizer = hasFinalizer;
|
561
|
+
|
562
|
+
/**
|
563
|
+
* Tracks the traversal position inside of the `try` statement. This is
|
564
|
+
* used to help determine the context necessary to create paths because
|
565
|
+
* a `try` statement may or may not have `catch` or `finally` blocks,
|
566
|
+
* and code paths behave differently in those blocks.
|
567
|
+
* @type {"try"|"catch"|"finally"}
|
568
|
+
*/
|
569
|
+
this.position = "try";
|
570
|
+
|
571
|
+
/**
|
572
|
+
* If the `try` statement has a `finally` block, this affects how a
|
573
|
+
* `return` statement behaves in the `try` block. Without `finally`,
|
574
|
+
* `return` behaves as usual and doesn't require a fork; with `finally`,
|
575
|
+
* `return` forks into the `finally` block, so we need a fork context
|
576
|
+
* to track it.
|
577
|
+
* @type {ForkContext|null}
|
578
|
+
*/
|
579
|
+
this.returnedForkContext = hasFinalizer
|
580
|
+
? ForkContext.newEmpty(forkContext)
|
581
|
+
: null;
|
582
|
+
|
583
|
+
/**
|
584
|
+
* When a `throw` occurs inside of a `try` block, the code path forks
|
585
|
+
* into the `catch` or `finally` blocks, and this fork context tracks
|
586
|
+
* that path.
|
587
|
+
* @type {ForkContext}
|
588
|
+
*/
|
589
|
+
this.thrownForkContext = ForkContext.newEmpty(forkContext);
|
590
|
+
|
591
|
+
/**
|
592
|
+
* Indicates if the last segment in the `try` block is reachable.
|
593
|
+
* @type {boolean}
|
594
|
+
*/
|
595
|
+
this.lastOfTryIsReachable = false;
|
596
|
+
|
597
|
+
/**
|
598
|
+
* Indicates if the last segment in the `catch` block is reachable.
|
599
|
+
* @type {boolean}
|
600
|
+
*/
|
601
|
+
this.lastOfCatchIsReachable = false;
|
602
|
+
}
|
622
603
|
}
|
623
604
|
|
624
605
|
//------------------------------------------------------------------------------
|
@@ -638,14 +619,14 @@ class TryContext {
|
|
638
619
|
* @returns {void}
|
639
620
|
*/
|
640
621
|
function addToReturnedOrThrown(dest, others, all, segments) {
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
622
|
+
for (let i = 0; i < segments.length; ++i) {
|
623
|
+
const segment = segments[i];
|
624
|
+
|
625
|
+
dest.push(segment);
|
626
|
+
if (!others.includes(segment)) {
|
627
|
+
all.push(segment);
|
628
|
+
}
|
629
|
+
}
|
649
630
|
}
|
650
631
|
|
651
632
|
/**
|
@@ -655,21 +636,21 @@ function addToReturnedOrThrown(dest, others, all, segments) {
|
|
655
636
|
* @returns {LoopContext} A loop-context for a `continue` statement.
|
656
637
|
*/
|
657
638
|
function getContinueContext(state, label) {
|
658
|
-
|
659
|
-
|
660
|
-
|
639
|
+
if (!label) {
|
640
|
+
return state.loopContext;
|
641
|
+
}
|
661
642
|
|
662
|
-
|
643
|
+
let context = state.loopContext;
|
663
644
|
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
645
|
+
while (context) {
|
646
|
+
if (context.label === label) {
|
647
|
+
return context;
|
648
|
+
}
|
649
|
+
context = context.upper;
|
650
|
+
}
|
670
651
|
|
671
|
-
|
672
|
-
|
652
|
+
/* c8 ignore next */
|
653
|
+
return null;
|
673
654
|
}
|
674
655
|
|
675
656
|
/**
|
@@ -679,17 +660,17 @@ function getContinueContext(state, label) {
|
|
679
660
|
* @returns {BreakContext} A context for a `break` statement.
|
680
661
|
*/
|
681
662
|
function getBreakContext(state, label) {
|
682
|
-
|
663
|
+
let context = state.breakContext;
|
683
664
|
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
665
|
+
while (context) {
|
666
|
+
if (label ? context.label === label : context.breakable) {
|
667
|
+
return context;
|
668
|
+
}
|
669
|
+
context = context.upper;
|
670
|
+
}
|
690
671
|
|
691
|
-
|
692
|
-
|
672
|
+
/* c8 ignore next */
|
673
|
+
return null;
|
693
674
|
}
|
694
675
|
|
695
676
|
/**
|
@@ -700,16 +681,16 @@ function getBreakContext(state, label) {
|
|
700
681
|
* @returns {TryContext|CodePathState} A context for a `return` statement.
|
701
682
|
*/
|
702
683
|
function getReturnContext(state) {
|
703
|
-
|
684
|
+
let context = state.tryContext;
|
704
685
|
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
686
|
+
while (context) {
|
687
|
+
if (context.hasFinalizer && context.position !== "finally") {
|
688
|
+
return context;
|
689
|
+
}
|
690
|
+
context = context.upper;
|
691
|
+
}
|
711
692
|
|
712
|
-
|
693
|
+
return state;
|
713
694
|
}
|
714
695
|
|
715
696
|
/**
|
@@ -721,18 +702,19 @@ function getReturnContext(state) {
|
|
721
702
|
* @returns {TryContext|CodePathState} A context for a `throw` statement.
|
722
703
|
*/
|
723
704
|
function getThrowContext(state) {
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
705
|
+
let context = state.tryContext;
|
706
|
+
|
707
|
+
while (context) {
|
708
|
+
if (
|
709
|
+
context.position === "try" ||
|
710
|
+
(context.hasFinalizer && context.position === "catch")
|
711
|
+
) {
|
712
|
+
return context;
|
713
|
+
}
|
714
|
+
context = context.upper;
|
715
|
+
}
|
716
|
+
|
717
|
+
return state;
|
736
718
|
}
|
737
719
|
|
738
720
|
/**
|
@@ -742,7 +724,7 @@ function getThrowContext(state) {
|
|
742
724
|
* @returns {void}
|
743
725
|
*/
|
744
726
|
function removeFromArray(elements, value) {
|
745
|
-
|
727
|
+
elements.splice(elements.indexOf(value), 1);
|
746
728
|
}
|
747
729
|
|
748
730
|
/**
|
@@ -756,15 +738,15 @@ function removeFromArray(elements, value) {
|
|
756
738
|
* @returns {void}
|
757
739
|
*/
|
758
740
|
function disconnectSegments(prevSegments, nextSegments) {
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
741
|
+
for (let i = 0; i < prevSegments.length; ++i) {
|
742
|
+
const prevSegment = prevSegments[i];
|
743
|
+
const nextSegment = nextSegments[i];
|
744
|
+
|
745
|
+
removeFromArray(prevSegment.nextSegments, nextSegment);
|
746
|
+
removeFromArray(prevSegment.allNextSegments, nextSegment);
|
747
|
+
removeFromArray(nextSegment.prevSegments, prevSegment);
|
748
|
+
removeFromArray(nextSegment.allPrevSegments, prevSegment);
|
749
|
+
}
|
768
750
|
}
|
769
751
|
|
770
752
|
/**
|
@@ -776,58 +758,60 @@ function disconnectSegments(prevSegments, nextSegments) {
|
|
776
758
|
* @returns {void}
|
777
759
|
*/
|
778
760
|
function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) {
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
761
|
+
const fromSegments = CodePathSegment.flattenUnusedSegments(
|
762
|
+
unflattenedFromSegments,
|
763
|
+
);
|
764
|
+
const toSegments = CodePathSegment.flattenUnusedSegments(
|
765
|
+
unflattenedToSegments,
|
766
|
+
);
|
767
|
+
const end = Math.min(fromSegments.length, toSegments.length);
|
768
|
+
|
769
|
+
/*
|
770
|
+
* This loop effectively updates a doubly-linked list between two collections
|
771
|
+
* of segments making sure that segments in the same array indices are
|
772
|
+
* combined to create a path.
|
773
|
+
*/
|
774
|
+
for (let i = 0; i < end; ++i) {
|
775
|
+
// get the segments in matching array indices
|
776
|
+
const fromSegment = fromSegments[i];
|
777
|
+
const toSegment = toSegments[i];
|
778
|
+
|
779
|
+
/*
|
780
|
+
* If the destination segment is reachable, then create a path from the
|
781
|
+
* source segment to the destination segment.
|
782
|
+
*/
|
783
|
+
if (toSegment.reachable) {
|
784
|
+
fromSegment.nextSegments.push(toSegment);
|
785
|
+
}
|
786
|
+
|
787
|
+
/*
|
788
|
+
* If the source segment is reachable, then create a path from the
|
789
|
+
* destination segment back to the source segment.
|
790
|
+
*/
|
791
|
+
if (fromSegment.reachable) {
|
792
|
+
toSegment.prevSegments.push(fromSegment);
|
793
|
+
}
|
794
|
+
|
795
|
+
/*
|
796
|
+
* Also update the arrays that don't care if the segments are reachable
|
797
|
+
* or not. This should always happen regardless of anything else.
|
798
|
+
*/
|
799
|
+
fromSegment.allNextSegments.push(toSegment);
|
800
|
+
toSegment.allPrevSegments.push(fromSegment);
|
801
|
+
|
802
|
+
/*
|
803
|
+
* If the destination segment has at least two previous segments in its
|
804
|
+
* path then that means there was one previous segment before this iteration
|
805
|
+
* of the loop was executed. So, we need to mark the source segment as
|
806
|
+
* looped.
|
807
|
+
*/
|
808
|
+
if (toSegment.allPrevSegments.length >= 2) {
|
809
|
+
CodePathSegment.markPrevSegmentAsLooped(toSegment, fromSegment);
|
810
|
+
}
|
811
|
+
|
812
|
+
// let the code path analyzer know that there's been a loop created
|
813
|
+
state.notifyLooped(fromSegment, toSegment);
|
814
|
+
}
|
831
815
|
}
|
832
816
|
|
833
817
|
/**
|
@@ -841,28 +825,27 @@ function makeLooped(state, unflattenedFromSegments, unflattenedToSegments) {
|
|
841
825
|
* @returns {void}
|
842
826
|
*/
|
843
827
|
function finalizeTestSegmentsOfFor(context, choiceContext, head) {
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
context.endOfTestSegments = choiceContext.trueForkContext.makeNext(0, -1);
|
828
|
+
/*
|
829
|
+
* If this choice context doesn't already contain paths from a
|
830
|
+
* child context, then add the current head to each potential path.
|
831
|
+
*/
|
832
|
+
if (!choiceContext.processed) {
|
833
|
+
choiceContext.trueForkContext.add(head);
|
834
|
+
choiceContext.falseForkContext.add(head);
|
835
|
+
choiceContext.nullishForkContext.add(head);
|
836
|
+
}
|
837
|
+
|
838
|
+
/*
|
839
|
+
* If the test condition isn't a hardcoded truthy value, then `break`
|
840
|
+
* must follow the same path as if the test condition is false. To represent
|
841
|
+
* that, we append the path for when the loop test is false (represented by
|
842
|
+
* `falseForkContext`) to the `brokenForkContext`.
|
843
|
+
*/
|
844
|
+
if (context.test !== true) {
|
845
|
+
context.brokenForkContext.addAll(choiceContext.falseForkContext);
|
846
|
+
}
|
847
|
+
|
848
|
+
context.endOfTestSegments = choiceContext.trueForkContext.makeNext(0, -1);
|
866
849
|
}
|
867
850
|
|
868
851
|
//------------------------------------------------------------------------------
|
@@ -873,1476 +856,1515 @@ function finalizeTestSegmentsOfFor(context, choiceContext, head) {
|
|
873
856
|
* A class which manages state to analyze code paths.
|
874
857
|
*/
|
875
858
|
class CodePathState {
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
|
1533
|
-
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
|
1540
|
-
|
1541
|
-
|
1542
|
-
|
1543
|
-
|
1544
|
-
|
1545
|
-
|
1546
|
-
|
1547
|
-
|
1548
|
-
|
1549
|
-
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1556
|
-
|
1557
|
-
|
1558
|
-
|
1559
|
-
|
1560
|
-
|
1561
|
-
|
1562
|
-
|
1563
|
-
|
1564
|
-
|
1565
|
-
|
1566
|
-
|
1567
|
-
|
1568
|
-
|
1569
|
-
|
1570
|
-
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1587
|
-
|
1588
|
-
|
1589
|
-
|
1590
|
-
|
1591
|
-
|
1592
|
-
|
1593
|
-
|
1594
|
-
|
1595
|
-
|
1596
|
-
|
1597
|
-
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
|
1602
|
-
|
1603
|
-
|
1604
|
-
|
1605
|
-
|
1606
|
-
|
1607
|
-
|
1608
|
-
|
1609
|
-
|
1610
|
-
|
1611
|
-
|
1612
|
-
|
1613
|
-
|
1614
|
-
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1619
|
-
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
|
1624
|
-
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1633
|
-
|
1634
|
-
|
1635
|
-
|
1636
|
-
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1640
|
-
|
1641
|
-
|
1642
|
-
|
1643
|
-
|
1644
|
-
|
1645
|
-
|
1646
|
-
|
1647
|
-
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1655
|
-
|
1656
|
-
|
1657
|
-
|
1658
|
-
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1703
|
-
|
1704
|
-
|
1705
|
-
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
|
1717
|
-
|
1718
|
-
|
1719
|
-
|
1720
|
-
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1725
|
-
|
1726
|
-
|
1727
|
-
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1732
|
-
|
1733
|
-
|
1734
|
-
|
1735
|
-
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1744
|
-
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
|
1757
|
-
|
1758
|
-
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1762
|
-
|
1763
|
-
|
1764
|
-
|
1765
|
-
|
1766
|
-
|
1767
|
-
|
1768
|
-
|
1769
|
-
|
1770
|
-
|
1771
|
-
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
|
1776
|
-
|
1777
|
-
|
1778
|
-
|
1779
|
-
|
1780
|
-
|
1781
|
-
|
1782
|
-
|
1783
|
-
|
1784
|
-
|
1785
|
-
|
1786
|
-
|
1787
|
-
|
1788
|
-
|
1789
|
-
|
1790
|
-
|
1791
|
-
|
1792
|
-
|
1793
|
-
|
1794
|
-
|
1795
|
-
|
1796
|
-
|
1797
|
-
|
1798
|
-
|
1799
|
-
|
1800
|
-
|
1801
|
-
|
1802
|
-
|
1803
|
-
|
1804
|
-
|
1805
|
-
|
1806
|
-
|
1807
|
-
|
1808
|
-
|
1809
|
-
|
1810
|
-
|
1811
|
-
|
1812
|
-
|
1813
|
-
|
1814
|
-
|
1815
|
-
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1847
|
-
|
1848
|
-
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
|
1863
|
-
|
1864
|
-
|
1865
|
-
|
1866
|
-
|
1867
|
-
|
1868
|
-
|
1869
|
-
|
1870
|
-
|
1871
|
-
|
1872
|
-
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
|
1885
|
-
|
1886
|
-
|
1887
|
-
|
1888
|
-
|
1889
|
-
|
1890
|
-
|
1891
|
-
|
1892
|
-
|
1893
|
-
|
1894
|
-
|
1895
|
-
|
1896
|
-
|
1897
|
-
|
1898
|
-
|
1899
|
-
|
1900
|
-
|
1901
|
-
|
1902
|
-
|
1903
|
-
|
1904
|
-
|
1905
|
-
|
1906
|
-
|
1907
|
-
|
1908
|
-
|
1909
|
-
|
1910
|
-
|
1911
|
-
|
1912
|
-
|
1913
|
-
|
1914
|
-
|
1915
|
-
|
1916
|
-
|
1917
|
-
|
1918
|
-
|
1919
|
-
|
1920
|
-
|
1921
|
-
|
1922
|
-
|
1923
|
-
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1930
|
-
|
1931
|
-
|
1932
|
-
|
1933
|
-
|
1934
|
-
|
1935
|
-
|
1936
|
-
|
1937
|
-
|
1938
|
-
|
1939
|
-
|
1940
|
-
|
1941
|
-
|
1942
|
-
|
1943
|
-
|
1944
|
-
|
1945
|
-
|
1946
|
-
|
1947
|
-
|
1948
|
-
|
1949
|
-
|
1950
|
-
|
1951
|
-
|
1952
|
-
|
1953
|
-
|
1954
|
-
|
1955
|
-
|
1956
|
-
|
1957
|
-
|
1958
|
-
|
1959
|
-
|
1960
|
-
|
1961
|
-
|
1962
|
-
|
1963
|
-
|
1964
|
-
|
1965
|
-
|
1966
|
-
|
1967
|
-
|
1968
|
-
|
1969
|
-
|
1970
|
-
|
1971
|
-
|
1972
|
-
|
1973
|
-
|
1974
|
-
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
|
1987
|
-
|
1988
|
-
|
1989
|
-
|
1990
|
-
|
1991
|
-
|
1992
|
-
|
1993
|
-
|
1994
|
-
|
1995
|
-
|
1996
|
-
|
1997
|
-
|
1998
|
-
|
1999
|
-
|
2000
|
-
|
2001
|
-
|
2002
|
-
|
2003
|
-
|
2004
|
-
|
2005
|
-
|
2006
|
-
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2011
|
-
|
2012
|
-
|
2013
|
-
|
2014
|
-
|
2015
|
-
|
2016
|
-
|
2017
|
-
|
2018
|
-
|
2019
|
-
|
2020
|
-
|
2021
|
-
|
2022
|
-
|
2023
|
-
|
2024
|
-
|
2025
|
-
|
2026
|
-
|
2027
|
-
|
2028
|
-
|
2029
|
-
|
2030
|
-
|
2031
|
-
|
2032
|
-
|
2033
|
-
|
2034
|
-
|
2035
|
-
|
2036
|
-
|
2037
|
-
|
2038
|
-
|
2039
|
-
|
2040
|
-
|
2041
|
-
|
2042
|
-
|
2043
|
-
|
2044
|
-
|
2045
|
-
|
2046
|
-
|
2047
|
-
|
2048
|
-
|
2049
|
-
|
2050
|
-
|
2051
|
-
|
2052
|
-
|
2053
|
-
|
2054
|
-
|
2055
|
-
|
2056
|
-
|
2057
|
-
|
2058
|
-
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2063
|
-
|
2064
|
-
|
2065
|
-
|
2066
|
-
|
2067
|
-
|
2068
|
-
|
2069
|
-
|
2070
|
-
|
2071
|
-
|
2072
|
-
|
2073
|
-
|
2074
|
-
|
2075
|
-
|
2076
|
-
|
2077
|
-
|
2078
|
-
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2083
|
-
|
2084
|
-
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2108
|
-
|
2109
|
-
|
2110
|
-
|
2111
|
-
|
2112
|
-
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
|
2118
|
-
|
2119
|
-
|
2120
|
-
|
2121
|
-
|
2122
|
-
|
2123
|
-
|
2124
|
-
|
2125
|
-
|
2126
|
-
|
2127
|
-
|
2128
|
-
|
2129
|
-
|
2130
|
-
|
2131
|
-
|
2132
|
-
|
2133
|
-
|
2134
|
-
|
2135
|
-
|
2136
|
-
|
2137
|
-
|
2138
|
-
|
2139
|
-
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2144
|
-
|
2145
|
-
|
2146
|
-
|
2147
|
-
|
2148
|
-
|
2149
|
-
|
2150
|
-
|
2151
|
-
|
2152
|
-
|
2153
|
-
|
2154
|
-
|
2155
|
-
|
2156
|
-
|
2157
|
-
|
2158
|
-
|
2159
|
-
|
2160
|
-
|
2161
|
-
|
2162
|
-
|
2163
|
-
|
2164
|
-
|
2165
|
-
|
2166
|
-
|
2167
|
-
|
2168
|
-
|
2169
|
-
|
2170
|
-
|
2171
|
-
|
2172
|
-
|
2173
|
-
|
2174
|
-
|
2175
|
-
|
2176
|
-
|
2177
|
-
|
2178
|
-
|
2179
|
-
|
2180
|
-
|
2181
|
-
|
2182
|
-
|
2183
|
-
|
2184
|
-
|
2185
|
-
|
2186
|
-
|
2187
|
-
|
2188
|
-
|
2189
|
-
|
2190
|
-
|
2191
|
-
|
2192
|
-
|
2193
|
-
|
2194
|
-
|
2195
|
-
|
2196
|
-
|
2197
|
-
|
2198
|
-
|
2199
|
-
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2205
|
-
|
2206
|
-
|
2207
|
-
|
2208
|
-
|
2209
|
-
|
2210
|
-
|
2211
|
-
|
2212
|
-
|
2213
|
-
|
2214
|
-
|
2215
|
-
|
2216
|
-
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2225
|
-
|
2226
|
-
|
2227
|
-
|
2228
|
-
|
2229
|
-
|
2230
|
-
|
2231
|
-
|
2232
|
-
|
2233
|
-
|
2234
|
-
|
2235
|
-
|
2236
|
-
|
2237
|
-
|
2238
|
-
|
2239
|
-
|
2240
|
-
|
2241
|
-
|
2242
|
-
|
2243
|
-
|
2244
|
-
|
2245
|
-
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2251
|
-
|
2252
|
-
|
2253
|
-
|
2254
|
-
|
2255
|
-
|
2256
|
-
|
2257
|
-
|
2258
|
-
|
2259
|
-
|
2260
|
-
|
2261
|
-
|
2262
|
-
|
2263
|
-
|
2264
|
-
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2268
|
-
|
2269
|
-
|
2270
|
-
|
2271
|
-
|
2272
|
-
|
2273
|
-
|
2274
|
-
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2278
|
-
|
2279
|
-
|
2280
|
-
|
2281
|
-
|
2282
|
-
|
2283
|
-
|
2284
|
-
|
2285
|
-
|
2286
|
-
|
2287
|
-
|
2288
|
-
|
2289
|
-
|
2290
|
-
|
2291
|
-
|
2292
|
-
|
2293
|
-
|
2294
|
-
|
2295
|
-
|
2296
|
-
|
2297
|
-
|
2298
|
-
|
2299
|
-
|
2300
|
-
|
2301
|
-
|
2302
|
-
|
2303
|
-
|
2304
|
-
|
2305
|
-
|
2306
|
-
|
2307
|
-
|
2308
|
-
|
2309
|
-
|
2310
|
-
|
2311
|
-
|
2312
|
-
|
2313
|
-
|
2314
|
-
|
2315
|
-
|
2316
|
-
|
2317
|
-
|
2318
|
-
|
2319
|
-
|
2320
|
-
|
2321
|
-
|
2322
|
-
|
2323
|
-
|
2324
|
-
|
2325
|
-
|
2326
|
-
|
2327
|
-
|
2328
|
-
|
2329
|
-
|
2330
|
-
|
2331
|
-
|
2332
|
-
|
2333
|
-
|
2334
|
-
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2338
|
-
|
2339
|
-
|
2340
|
-
|
2341
|
-
|
2342
|
-
|
2343
|
-
|
2344
|
-
|
2345
|
-
|
859
|
+
/**
|
860
|
+
* Creates a new instance.
|
861
|
+
* @param {IdGenerator} idGenerator An id generator to generate id for code
|
862
|
+
* path segments.
|
863
|
+
* @param {Function} onLooped A callback function to notify looping.
|
864
|
+
*/
|
865
|
+
constructor(idGenerator, onLooped) {
|
866
|
+
/**
|
867
|
+
* The ID generator to use when creating new segments.
|
868
|
+
* @type {IdGenerator}
|
869
|
+
*/
|
870
|
+
this.idGenerator = idGenerator;
|
871
|
+
|
872
|
+
/**
|
873
|
+
* A callback function to call when there is a loop.
|
874
|
+
* @type {Function}
|
875
|
+
*/
|
876
|
+
this.notifyLooped = onLooped;
|
877
|
+
|
878
|
+
/**
|
879
|
+
* The root fork context for this state.
|
880
|
+
* @type {ForkContext}
|
881
|
+
*/
|
882
|
+
this.forkContext = ForkContext.newRoot(idGenerator);
|
883
|
+
|
884
|
+
/**
|
885
|
+
* Context for logical expressions, conditional expressions, `if` statements,
|
886
|
+
* and loops.
|
887
|
+
* @type {ChoiceContext}
|
888
|
+
*/
|
889
|
+
this.choiceContext = null;
|
890
|
+
|
891
|
+
/**
|
892
|
+
* Context for `switch` statements.
|
893
|
+
* @type {SwitchContext}
|
894
|
+
*/
|
895
|
+
this.switchContext = null;
|
896
|
+
|
897
|
+
/**
|
898
|
+
* Context for `try` statements.
|
899
|
+
* @type {TryContext}
|
900
|
+
*/
|
901
|
+
this.tryContext = null;
|
902
|
+
|
903
|
+
/**
|
904
|
+
* Context for loop statements.
|
905
|
+
* @type {LoopContext}
|
906
|
+
*/
|
907
|
+
this.loopContext = null;
|
908
|
+
|
909
|
+
/**
|
910
|
+
* Context for `break` statements.
|
911
|
+
* @type {BreakContext}
|
912
|
+
*/
|
913
|
+
this.breakContext = null;
|
914
|
+
|
915
|
+
/**
|
916
|
+
* Context for `ChainExpression` nodes.
|
917
|
+
* @type {ChainContext}
|
918
|
+
*/
|
919
|
+
this.chainContext = null;
|
920
|
+
|
921
|
+
/**
|
922
|
+
* An array that tracks the current segments in the state. The array
|
923
|
+
* starts empty and segments are added with each `onCodePathSegmentStart`
|
924
|
+
* event and removed with each `onCodePathSegmentEnd` event. Effectively,
|
925
|
+
* this is tracking the code path segment traversal as the state is
|
926
|
+
* modified.
|
927
|
+
* @type {Array<CodePathSegment>}
|
928
|
+
*/
|
929
|
+
this.currentSegments = [];
|
930
|
+
|
931
|
+
/**
|
932
|
+
* Tracks the starting segment for this path. This value never changes.
|
933
|
+
* @type {CodePathSegment}
|
934
|
+
*/
|
935
|
+
this.initialSegment = this.forkContext.head[0];
|
936
|
+
|
937
|
+
/**
|
938
|
+
* The final segments of the code path which are either `return` or `throw`.
|
939
|
+
* This is a union of the segments in `returnedForkContext` and `thrownForkContext`.
|
940
|
+
* @type {Array<CodePathSegment>}
|
941
|
+
*/
|
942
|
+
this.finalSegments = [];
|
943
|
+
|
944
|
+
/**
|
945
|
+
* The final segments of the code path which are `return`. These
|
946
|
+
* segments are also contained in `finalSegments`.
|
947
|
+
* @type {Array<CodePathSegment>}
|
948
|
+
*/
|
949
|
+
this.returnedForkContext = [];
|
950
|
+
|
951
|
+
/**
|
952
|
+
* The final segments of the code path which are `throw`. These
|
953
|
+
* segments are also contained in `finalSegments`.
|
954
|
+
* @type {Array<CodePathSegment>}
|
955
|
+
*/
|
956
|
+
this.thrownForkContext = [];
|
957
|
+
|
958
|
+
/*
|
959
|
+
* We add an `add` method so that these look more like fork contexts and
|
960
|
+
* can be used interchangeably when a fork context is needed to add more
|
961
|
+
* segments to a path.
|
962
|
+
*
|
963
|
+
* Ultimately, we want anything added to `returned` or `thrown` to also
|
964
|
+
* be added to `final`. We only add reachable and used segments to these
|
965
|
+
* arrays.
|
966
|
+
*/
|
967
|
+
const final = this.finalSegments;
|
968
|
+
const returned = this.returnedForkContext;
|
969
|
+
const thrown = this.thrownForkContext;
|
970
|
+
|
971
|
+
returned.add = addToReturnedOrThrown.bind(
|
972
|
+
null,
|
973
|
+
returned,
|
974
|
+
thrown,
|
975
|
+
final,
|
976
|
+
);
|
977
|
+
thrown.add = addToReturnedOrThrown.bind(null, thrown, returned, final);
|
978
|
+
}
|
979
|
+
|
980
|
+
/**
|
981
|
+
* A passthrough property exposing the current pointer as part of the API.
|
982
|
+
* @type {CodePathSegment[]}
|
983
|
+
*/
|
984
|
+
get headSegments() {
|
985
|
+
return this.forkContext.head;
|
986
|
+
}
|
987
|
+
|
988
|
+
/**
|
989
|
+
* The parent forking context.
|
990
|
+
* This is used for the root of new forks.
|
991
|
+
* @type {ForkContext}
|
992
|
+
*/
|
993
|
+
get parentForkContext() {
|
994
|
+
const current = this.forkContext;
|
995
|
+
|
996
|
+
return current && current.upper;
|
997
|
+
}
|
998
|
+
|
999
|
+
/**
|
1000
|
+
* Creates and stacks new forking context.
|
1001
|
+
* @param {boolean} forkLeavingPath A flag which shows being in a
|
1002
|
+
* "finally" block.
|
1003
|
+
* @returns {ForkContext} The created context.
|
1004
|
+
*/
|
1005
|
+
pushForkContext(forkLeavingPath) {
|
1006
|
+
this.forkContext = ForkContext.newEmpty(
|
1007
|
+
this.forkContext,
|
1008
|
+
forkLeavingPath,
|
1009
|
+
);
|
1010
|
+
|
1011
|
+
return this.forkContext;
|
1012
|
+
}
|
1013
|
+
|
1014
|
+
/**
|
1015
|
+
* Pops and merges the last forking context.
|
1016
|
+
* @returns {ForkContext} The last context.
|
1017
|
+
*/
|
1018
|
+
popForkContext() {
|
1019
|
+
const lastContext = this.forkContext;
|
1020
|
+
|
1021
|
+
this.forkContext = lastContext.upper;
|
1022
|
+
this.forkContext.replaceHead(lastContext.makeNext(0, -1));
|
1023
|
+
|
1024
|
+
return lastContext;
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
/**
|
1028
|
+
* Creates a new path.
|
1029
|
+
* @returns {void}
|
1030
|
+
*/
|
1031
|
+
forkPath() {
|
1032
|
+
this.forkContext.add(this.parentForkContext.makeNext(-1, -1));
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
/**
|
1036
|
+
* Creates a bypass path.
|
1037
|
+
* This is used for such as IfStatement which does not have "else" chunk.
|
1038
|
+
* @returns {void}
|
1039
|
+
*/
|
1040
|
+
forkBypassPath() {
|
1041
|
+
this.forkContext.add(this.parentForkContext.head);
|
1042
|
+
}
|
1043
|
+
|
1044
|
+
//--------------------------------------------------------------------------
|
1045
|
+
// ConditionalExpression, LogicalExpression, IfStatement
|
1046
|
+
//--------------------------------------------------------------------------
|
1047
|
+
|
1048
|
+
/**
|
1049
|
+
* Creates a context for ConditionalExpression, LogicalExpression, AssignmentExpression (logical assignments only),
|
1050
|
+
* IfStatement, WhileStatement, DoWhileStatement, or ForStatement.
|
1051
|
+
*
|
1052
|
+
* LogicalExpressions have cases that it goes different paths between the
|
1053
|
+
* `true` case and the `false` case.
|
1054
|
+
*
|
1055
|
+
* For Example:
|
1056
|
+
*
|
1057
|
+
* if (a || b) {
|
1058
|
+
* foo();
|
1059
|
+
* } else {
|
1060
|
+
* bar();
|
1061
|
+
* }
|
1062
|
+
*
|
1063
|
+
* In this case, `b` is evaluated always in the code path of the `else`
|
1064
|
+
* block, but it's not so in the code path of the `if` block.
|
1065
|
+
* So there are 3 paths.
|
1066
|
+
*
|
1067
|
+
* a -> foo();
|
1068
|
+
* a -> b -> foo();
|
1069
|
+
* a -> b -> bar();
|
1070
|
+
* @param {string} kind A kind string.
|
1071
|
+
* If the new context is LogicalExpression's or AssignmentExpression's, this is `"&&"` or `"||"` or `"??"`.
|
1072
|
+
* If it's IfStatement's or ConditionalExpression's, this is `"test"`.
|
1073
|
+
* Otherwise, this is `"loop"`.
|
1074
|
+
* @param {boolean} isForkingAsResult Indicates if the result of the choice
|
1075
|
+
* creates a fork.
|
1076
|
+
* @returns {void}
|
1077
|
+
*/
|
1078
|
+
pushChoiceContext(kind, isForkingAsResult) {
|
1079
|
+
this.choiceContext = new ChoiceContext(
|
1080
|
+
this.choiceContext,
|
1081
|
+
kind,
|
1082
|
+
isForkingAsResult,
|
1083
|
+
this.forkContext,
|
1084
|
+
);
|
1085
|
+
}
|
1086
|
+
|
1087
|
+
/**
|
1088
|
+
* Pops the last choice context and finalizes it.
|
1089
|
+
* This is called upon leaving a node that represents a choice.
|
1090
|
+
* @throws {Error} (Unreachable.)
|
1091
|
+
* @returns {ChoiceContext} The popped context.
|
1092
|
+
*/
|
1093
|
+
popChoiceContext() {
|
1094
|
+
const poppedChoiceContext = this.choiceContext;
|
1095
|
+
const forkContext = this.forkContext;
|
1096
|
+
const head = forkContext.head;
|
1097
|
+
|
1098
|
+
this.choiceContext = poppedChoiceContext.upper;
|
1099
|
+
|
1100
|
+
switch (poppedChoiceContext.kind) {
|
1101
|
+
case "&&":
|
1102
|
+
case "||":
|
1103
|
+
case "??":
|
1104
|
+
/*
|
1105
|
+
* The `head` are the path of the right-hand operand.
|
1106
|
+
* If we haven't previously added segments from child contexts,
|
1107
|
+
* then we add these segments to all possible forks.
|
1108
|
+
*/
|
1109
|
+
if (!poppedChoiceContext.processed) {
|
1110
|
+
poppedChoiceContext.trueForkContext.add(head);
|
1111
|
+
poppedChoiceContext.falseForkContext.add(head);
|
1112
|
+
poppedChoiceContext.nullishForkContext.add(head);
|
1113
|
+
}
|
1114
|
+
|
1115
|
+
/*
|
1116
|
+
* If this context is the left (test) expression for another choice
|
1117
|
+
* context, such as `a || b` in the expression `a || b || c`,
|
1118
|
+
* then we take the segments for this context and move them up
|
1119
|
+
* to the parent context.
|
1120
|
+
*/
|
1121
|
+
if (poppedChoiceContext.isForkingAsResult) {
|
1122
|
+
const parentContext = this.choiceContext;
|
1123
|
+
|
1124
|
+
parentContext.trueForkContext.addAll(
|
1125
|
+
poppedChoiceContext.trueForkContext,
|
1126
|
+
);
|
1127
|
+
parentContext.falseForkContext.addAll(
|
1128
|
+
poppedChoiceContext.falseForkContext,
|
1129
|
+
);
|
1130
|
+
parentContext.nullishForkContext.addAll(
|
1131
|
+
poppedChoiceContext.nullishForkContext,
|
1132
|
+
);
|
1133
|
+
parentContext.processed = true;
|
1134
|
+
|
1135
|
+
// Exit early so we don't collapse all paths into one.
|
1136
|
+
return poppedChoiceContext;
|
1137
|
+
}
|
1138
|
+
|
1139
|
+
break;
|
1140
|
+
|
1141
|
+
case "test":
|
1142
|
+
if (!poppedChoiceContext.processed) {
|
1143
|
+
/*
|
1144
|
+
* The head segments are the path of the `if` block here.
|
1145
|
+
* Updates the `true` path with the end of the `if` block.
|
1146
|
+
*/
|
1147
|
+
poppedChoiceContext.trueForkContext.clear();
|
1148
|
+
poppedChoiceContext.trueForkContext.add(head);
|
1149
|
+
} else {
|
1150
|
+
/*
|
1151
|
+
* The head segments are the path of the `else` block here.
|
1152
|
+
* Updates the `false` path with the end of the `else`
|
1153
|
+
* block.
|
1154
|
+
*/
|
1155
|
+
poppedChoiceContext.falseForkContext.clear();
|
1156
|
+
poppedChoiceContext.falseForkContext.add(head);
|
1157
|
+
}
|
1158
|
+
|
1159
|
+
break;
|
1160
|
+
|
1161
|
+
case "loop":
|
1162
|
+
/*
|
1163
|
+
* Loops are addressed in `popLoopContext()` so just return
|
1164
|
+
* the context without modification.
|
1165
|
+
*/
|
1166
|
+
return poppedChoiceContext;
|
1167
|
+
|
1168
|
+
/* c8 ignore next */
|
1169
|
+
default:
|
1170
|
+
throw new Error("unreachable");
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
/*
|
1174
|
+
* Merge the true path with the false path to create a single path.
|
1175
|
+
*/
|
1176
|
+
const combinedForkContext = poppedChoiceContext.trueForkContext;
|
1177
|
+
|
1178
|
+
combinedForkContext.addAll(poppedChoiceContext.falseForkContext);
|
1179
|
+
forkContext.replaceHead(combinedForkContext.makeNext(0, -1));
|
1180
|
+
|
1181
|
+
return poppedChoiceContext;
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
/**
|
1185
|
+
* Creates a code path segment to represent right-hand operand of a logical
|
1186
|
+
* expression.
|
1187
|
+
* This is called in the preprocessing phase when entering a node.
|
1188
|
+
* @throws {Error} (Unreachable.)
|
1189
|
+
* @returns {void}
|
1190
|
+
*/
|
1191
|
+
makeLogicalRight() {
|
1192
|
+
const currentChoiceContext = this.choiceContext;
|
1193
|
+
const forkContext = this.forkContext;
|
1194
|
+
|
1195
|
+
if (currentChoiceContext.processed) {
|
1196
|
+
/*
|
1197
|
+
* This context was already assigned segments from a child
|
1198
|
+
* choice context. In this case, we are concerned only about
|
1199
|
+
* the path that does not short-circuit and so ends up on the
|
1200
|
+
* right-hand operand of the logical expression.
|
1201
|
+
*/
|
1202
|
+
let prevForkContext;
|
1203
|
+
|
1204
|
+
switch (currentChoiceContext.kind) {
|
1205
|
+
case "&&": // if true then go to the right-hand side.
|
1206
|
+
prevForkContext = currentChoiceContext.trueForkContext;
|
1207
|
+
break;
|
1208
|
+
case "||": // if false then go to the right-hand side.
|
1209
|
+
prevForkContext = currentChoiceContext.falseForkContext;
|
1210
|
+
break;
|
1211
|
+
case "??": // Both true/false can short-circuit, so needs the third path to go to the right-hand side. That's nullishForkContext.
|
1212
|
+
prevForkContext = currentChoiceContext.nullishForkContext;
|
1213
|
+
break;
|
1214
|
+
default:
|
1215
|
+
throw new Error("unreachable");
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
/*
|
1219
|
+
* Create the segment for the right-hand operand of the logical expression
|
1220
|
+
* and adjust the fork context pointer to point there. The right-hand segment
|
1221
|
+
* is added at the end of all segments in `prevForkContext`.
|
1222
|
+
*/
|
1223
|
+
forkContext.replaceHead(prevForkContext.makeNext(0, -1));
|
1224
|
+
|
1225
|
+
/*
|
1226
|
+
* We no longer need this list of segments.
|
1227
|
+
*
|
1228
|
+
* Reset `processed` because we've removed the segments from the child
|
1229
|
+
* choice context. This allows `popChoiceContext()` to continue adding
|
1230
|
+
* segments later.
|
1231
|
+
*/
|
1232
|
+
prevForkContext.clear();
|
1233
|
+
currentChoiceContext.processed = false;
|
1234
|
+
} else {
|
1235
|
+
/*
|
1236
|
+
* This choice context was not assigned segments from a child
|
1237
|
+
* choice context, which means that it's a terminal logical
|
1238
|
+
* expression.
|
1239
|
+
*
|
1240
|
+
* `head` is the segments for the left-hand operand of the
|
1241
|
+
* logical expression.
|
1242
|
+
*
|
1243
|
+
* Each of the fork contexts below are empty at this point. We choose
|
1244
|
+
* the path(s) that will short-circuit and add the segment for the
|
1245
|
+
* left-hand operand to it. Ultimately, this will be the only segment
|
1246
|
+
* in that path due to the short-circuting, so we are just seeding
|
1247
|
+
* these paths to start.
|
1248
|
+
*/
|
1249
|
+
switch (currentChoiceContext.kind) {
|
1250
|
+
case "&&":
|
1251
|
+
/*
|
1252
|
+
* In most contexts, when a && expression evaluates to false,
|
1253
|
+
* it short circuits, so we need to account for that by setting
|
1254
|
+
* the `falseForkContext` to the left operand.
|
1255
|
+
*
|
1256
|
+
* When a && expression is the left-hand operand for a ??
|
1257
|
+
* expression, such as `(a && b) ?? c`, a nullish value will
|
1258
|
+
* also short-circuit in a different way than a false value,
|
1259
|
+
* so we also set the `nullishForkContext` to the left operand.
|
1260
|
+
* This path is only used with a ?? expression and is thrown
|
1261
|
+
* away for any other type of logical expression, so it's safe
|
1262
|
+
* to always add.
|
1263
|
+
*/
|
1264
|
+
currentChoiceContext.falseForkContext.add(forkContext.head);
|
1265
|
+
currentChoiceContext.nullishForkContext.add(
|
1266
|
+
forkContext.head,
|
1267
|
+
);
|
1268
|
+
break;
|
1269
|
+
case "||": // the true path can short-circuit.
|
1270
|
+
currentChoiceContext.trueForkContext.add(forkContext.head);
|
1271
|
+
break;
|
1272
|
+
case "??": // both can short-circuit.
|
1273
|
+
currentChoiceContext.trueForkContext.add(forkContext.head);
|
1274
|
+
currentChoiceContext.falseForkContext.add(forkContext.head);
|
1275
|
+
break;
|
1276
|
+
default:
|
1277
|
+
throw new Error("unreachable");
|
1278
|
+
}
|
1279
|
+
|
1280
|
+
/*
|
1281
|
+
* Create the segment for the right-hand operand of the logical expression
|
1282
|
+
* and adjust the fork context pointer to point there.
|
1283
|
+
*/
|
1284
|
+
forkContext.replaceHead(forkContext.makeNext(-1, -1));
|
1285
|
+
}
|
1286
|
+
}
|
1287
|
+
|
1288
|
+
/**
|
1289
|
+
* Makes a code path segment of the `if` block.
|
1290
|
+
* @returns {void}
|
1291
|
+
*/
|
1292
|
+
makeIfConsequent() {
|
1293
|
+
const context = this.choiceContext;
|
1294
|
+
const forkContext = this.forkContext;
|
1295
|
+
|
1296
|
+
/*
|
1297
|
+
* If any result were not transferred from child contexts,
|
1298
|
+
* this sets the head segments to both cases.
|
1299
|
+
* The head segments are the path of the test expression.
|
1300
|
+
*/
|
1301
|
+
if (!context.processed) {
|
1302
|
+
context.trueForkContext.add(forkContext.head);
|
1303
|
+
context.falseForkContext.add(forkContext.head);
|
1304
|
+
context.nullishForkContext.add(forkContext.head);
|
1305
|
+
}
|
1306
|
+
|
1307
|
+
context.processed = false;
|
1308
|
+
|
1309
|
+
// Creates new path from the `true` case.
|
1310
|
+
forkContext.replaceHead(context.trueForkContext.makeNext(0, -1));
|
1311
|
+
}
|
1312
|
+
|
1313
|
+
/**
|
1314
|
+
* Makes a code path segment of the `else` block.
|
1315
|
+
* @returns {void}
|
1316
|
+
*/
|
1317
|
+
makeIfAlternate() {
|
1318
|
+
const context = this.choiceContext;
|
1319
|
+
const forkContext = this.forkContext;
|
1320
|
+
|
1321
|
+
/*
|
1322
|
+
* The head segments are the path of the `if` block.
|
1323
|
+
* Updates the `true` path with the end of the `if` block.
|
1324
|
+
*/
|
1325
|
+
context.trueForkContext.clear();
|
1326
|
+
context.trueForkContext.add(forkContext.head);
|
1327
|
+
context.processed = true;
|
1328
|
+
|
1329
|
+
// Creates new path from the `false` case.
|
1330
|
+
forkContext.replaceHead(context.falseForkContext.makeNext(0, -1));
|
1331
|
+
}
|
1332
|
+
|
1333
|
+
//--------------------------------------------------------------------------
|
1334
|
+
// ChainExpression
|
1335
|
+
//--------------------------------------------------------------------------
|
1336
|
+
|
1337
|
+
/**
|
1338
|
+
* Pushes a new `ChainExpression` context to the stack. This method is
|
1339
|
+
* called when entering a `ChainExpression` node. A chain context is used to
|
1340
|
+
* count forking in the optional chain then merge them on the exiting from the
|
1341
|
+
* `ChainExpression` node.
|
1342
|
+
* @returns {void}
|
1343
|
+
*/
|
1344
|
+
pushChainContext() {
|
1345
|
+
this.chainContext = new ChainContext(this.chainContext);
|
1346
|
+
}
|
1347
|
+
|
1348
|
+
/**
|
1349
|
+
* Pop a `ChainExpression` context from the stack. This method is called on
|
1350
|
+
* exiting from each `ChainExpression` node. This merges all forks of the
|
1351
|
+
* last optional chaining.
|
1352
|
+
* @returns {void}
|
1353
|
+
*/
|
1354
|
+
popChainContext() {
|
1355
|
+
const context = this.chainContext;
|
1356
|
+
|
1357
|
+
this.chainContext = context.upper;
|
1358
|
+
|
1359
|
+
// pop all choice contexts of this.
|
1360
|
+
for (let i = context.choiceContextCount; i > 0; --i) {
|
1361
|
+
this.popChoiceContext();
|
1362
|
+
}
|
1363
|
+
}
|
1364
|
+
|
1365
|
+
/**
|
1366
|
+
* Create a choice context for optional access.
|
1367
|
+
* This method is called on entering to each `(Call|Member)Expression[optional=true]` node.
|
1368
|
+
* This creates a choice context as similar to `LogicalExpression[operator="??"]` node.
|
1369
|
+
* @returns {void}
|
1370
|
+
*/
|
1371
|
+
makeOptionalNode() {
|
1372
|
+
if (this.chainContext) {
|
1373
|
+
this.chainContext.choiceContextCount += 1;
|
1374
|
+
this.pushChoiceContext("??", false);
|
1375
|
+
}
|
1376
|
+
}
|
1377
|
+
|
1378
|
+
/**
|
1379
|
+
* Create a fork.
|
1380
|
+
* This method is called on entering to the `arguments|property` property of each `(Call|Member)Expression` node.
|
1381
|
+
* @returns {void}
|
1382
|
+
*/
|
1383
|
+
makeOptionalRight() {
|
1384
|
+
if (this.chainContext) {
|
1385
|
+
this.makeLogicalRight();
|
1386
|
+
}
|
1387
|
+
}
|
1388
|
+
|
1389
|
+
//--------------------------------------------------------------------------
|
1390
|
+
// SwitchStatement
|
1391
|
+
//--------------------------------------------------------------------------
|
1392
|
+
|
1393
|
+
/**
|
1394
|
+
* Creates a context object of SwitchStatement and stacks it.
|
1395
|
+
* @param {boolean} hasCase `true` if the switch statement has one or more
|
1396
|
+
* case parts.
|
1397
|
+
* @param {string|null} label The label text.
|
1398
|
+
* @returns {void}
|
1399
|
+
*/
|
1400
|
+
pushSwitchContext(hasCase, label) {
|
1401
|
+
this.switchContext = new SwitchContext(this.switchContext, hasCase);
|
1402
|
+
this.pushBreakContext(true, label);
|
1403
|
+
}
|
1404
|
+
|
1405
|
+
/**
|
1406
|
+
* Pops the last context of SwitchStatement and finalizes it.
|
1407
|
+
*
|
1408
|
+
* - Disposes all forking stack for `case` and `default`.
|
1409
|
+
* - Creates the next code path segment from `context.brokenForkContext`.
|
1410
|
+
* - If the last `SwitchCase` node is not a `default` part, creates a path
|
1411
|
+
* to the `default` body.
|
1412
|
+
* @returns {void}
|
1413
|
+
*/
|
1414
|
+
popSwitchContext() {
|
1415
|
+
const context = this.switchContext;
|
1416
|
+
|
1417
|
+
this.switchContext = context.upper;
|
1418
|
+
|
1419
|
+
const forkContext = this.forkContext;
|
1420
|
+
const brokenForkContext = this.popBreakContext().brokenForkContext;
|
1421
|
+
|
1422
|
+
if (context.forkCount === 0) {
|
1423
|
+
/*
|
1424
|
+
* When there is only one `default` chunk and there is one or more
|
1425
|
+
* `break` statements, even if forks are nothing, it needs to merge
|
1426
|
+
* those.
|
1427
|
+
*/
|
1428
|
+
if (!brokenForkContext.empty) {
|
1429
|
+
brokenForkContext.add(forkContext.makeNext(-1, -1));
|
1430
|
+
forkContext.replaceHead(brokenForkContext.makeNext(0, -1));
|
1431
|
+
}
|
1432
|
+
|
1433
|
+
return;
|
1434
|
+
}
|
1435
|
+
|
1436
|
+
const lastSegments = forkContext.head;
|
1437
|
+
|
1438
|
+
this.forkBypassPath();
|
1439
|
+
const lastCaseSegments = forkContext.head;
|
1440
|
+
|
1441
|
+
/*
|
1442
|
+
* `brokenForkContext` is used to make the next segment.
|
1443
|
+
* It must add the last segment into `brokenForkContext`.
|
1444
|
+
*/
|
1445
|
+
brokenForkContext.add(lastSegments);
|
1446
|
+
|
1447
|
+
/*
|
1448
|
+
* Any value that doesn't match a `case` test should flow to the default
|
1449
|
+
* case. That happens normally when the default case is last in the `switch`,
|
1450
|
+
* but if it's not, we need to rewire some of the paths to be correct.
|
1451
|
+
*/
|
1452
|
+
if (!context.lastIsDefault) {
|
1453
|
+
if (context.defaultBodySegments) {
|
1454
|
+
/*
|
1455
|
+
* There is a non-empty default case, so remove the path from the `default`
|
1456
|
+
* label to its body for an accurate representation.
|
1457
|
+
*/
|
1458
|
+
disconnectSegments(
|
1459
|
+
context.defaultSegments,
|
1460
|
+
context.defaultBodySegments,
|
1461
|
+
);
|
1462
|
+
|
1463
|
+
/*
|
1464
|
+
* Connect the path from the last non-default case to the body of the
|
1465
|
+
* default case.
|
1466
|
+
*/
|
1467
|
+
makeLooped(this, lastCaseSegments, context.defaultBodySegments);
|
1468
|
+
} else {
|
1469
|
+
/*
|
1470
|
+
* There is no default case, so we treat this as if the last case
|
1471
|
+
* had a `break` in it.
|
1472
|
+
*/
|
1473
|
+
brokenForkContext.add(lastCaseSegments);
|
1474
|
+
}
|
1475
|
+
}
|
1476
|
+
|
1477
|
+
// Traverse up to the original fork context for the `switch` statement
|
1478
|
+
for (let i = 0; i < context.forkCount; ++i) {
|
1479
|
+
this.forkContext = this.forkContext.upper;
|
1480
|
+
}
|
1481
|
+
|
1482
|
+
/*
|
1483
|
+
* Creates a path from all `brokenForkContext` paths.
|
1484
|
+
* This is a path after `switch` statement.
|
1485
|
+
*/
|
1486
|
+
this.forkContext.replaceHead(brokenForkContext.makeNext(0, -1));
|
1487
|
+
}
|
1488
|
+
|
1489
|
+
/**
|
1490
|
+
* Makes a code path segment for a `SwitchCase` node.
|
1491
|
+
* @param {boolean} isCaseBodyEmpty `true` if the body is empty.
|
1492
|
+
* @param {boolean} isDefaultCase `true` if the body is the default case.
|
1493
|
+
* @returns {void}
|
1494
|
+
*/
|
1495
|
+
makeSwitchCaseBody(isCaseBodyEmpty, isDefaultCase) {
|
1496
|
+
const context = this.switchContext;
|
1497
|
+
|
1498
|
+
if (!context.hasCase) {
|
1499
|
+
return;
|
1500
|
+
}
|
1501
|
+
|
1502
|
+
/*
|
1503
|
+
* Merge forks.
|
1504
|
+
* The parent fork context has two segments.
|
1505
|
+
* Those are from the current `case` and the body of the previous case.
|
1506
|
+
*/
|
1507
|
+
const parentForkContext = this.forkContext;
|
1508
|
+
const forkContext = this.pushForkContext();
|
1509
|
+
|
1510
|
+
forkContext.add(parentForkContext.makeNext(0, -1));
|
1511
|
+
|
1512
|
+
/*
|
1513
|
+
* Add information about the default case.
|
1514
|
+
*
|
1515
|
+
* The purpose of this is to identify the starting segments for the
|
1516
|
+
* default case to make sure there is a path there.
|
1517
|
+
*/
|
1518
|
+
if (isDefaultCase) {
|
1519
|
+
/*
|
1520
|
+
* This is the default case in the `switch`.
|
1521
|
+
*
|
1522
|
+
* We first save the current pointer as `defaultSegments` to point
|
1523
|
+
* to the `default` keyword.
|
1524
|
+
*/
|
1525
|
+
context.defaultSegments = parentForkContext.head;
|
1526
|
+
|
1527
|
+
/*
|
1528
|
+
* If the body of the case is empty then we just set
|
1529
|
+
* `foundEmptyDefault` to true; otherwise, we save a reference
|
1530
|
+
* to the current pointer as `defaultBodySegments`.
|
1531
|
+
*/
|
1532
|
+
if (isCaseBodyEmpty) {
|
1533
|
+
context.foundEmptyDefault = true;
|
1534
|
+
} else {
|
1535
|
+
context.defaultBodySegments = forkContext.head;
|
1536
|
+
}
|
1537
|
+
} else {
|
1538
|
+
/*
|
1539
|
+
* This is not the default case in the `switch`.
|
1540
|
+
*
|
1541
|
+
* If it's not empty and there is already an empty default case found,
|
1542
|
+
* that means the default case actually comes before this case,
|
1543
|
+
* and that it will fall through to this case. So, we can now
|
1544
|
+
* ignore the previous default case (reset `foundEmptyDefault` to false)
|
1545
|
+
* and set `defaultBodySegments` to the current segments because this is
|
1546
|
+
* effectively the new default case.
|
1547
|
+
*/
|
1548
|
+
if (!isCaseBodyEmpty && context.foundEmptyDefault) {
|
1549
|
+
context.foundEmptyDefault = false;
|
1550
|
+
context.defaultBodySegments = forkContext.head;
|
1551
|
+
}
|
1552
|
+
}
|
1553
|
+
|
1554
|
+
// keep track if the default case ends up last
|
1555
|
+
context.lastIsDefault = isDefaultCase;
|
1556
|
+
context.forkCount += 1;
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
//--------------------------------------------------------------------------
|
1560
|
+
// TryStatement
|
1561
|
+
//--------------------------------------------------------------------------
|
1562
|
+
|
1563
|
+
/**
|
1564
|
+
* Creates a context object of TryStatement and stacks it.
|
1565
|
+
* @param {boolean} hasFinalizer `true` if the try statement has a
|
1566
|
+
* `finally` block.
|
1567
|
+
* @returns {void}
|
1568
|
+
*/
|
1569
|
+
pushTryContext(hasFinalizer) {
|
1570
|
+
this.tryContext = new TryContext(
|
1571
|
+
this.tryContext,
|
1572
|
+
hasFinalizer,
|
1573
|
+
this.forkContext,
|
1574
|
+
);
|
1575
|
+
}
|
1576
|
+
|
1577
|
+
/**
|
1578
|
+
* Pops the last context of TryStatement and finalizes it.
|
1579
|
+
* @returns {void}
|
1580
|
+
*/
|
1581
|
+
popTryContext() {
|
1582
|
+
const context = this.tryContext;
|
1583
|
+
|
1584
|
+
this.tryContext = context.upper;
|
1585
|
+
|
1586
|
+
/*
|
1587
|
+
* If we're inside the `catch` block, that means there is no `finally`,
|
1588
|
+
* so we can process the `try` and `catch` blocks the simple way and
|
1589
|
+
* merge their two paths.
|
1590
|
+
*/
|
1591
|
+
if (context.position === "catch") {
|
1592
|
+
this.popForkContext();
|
1593
|
+
return;
|
1594
|
+
}
|
1595
|
+
|
1596
|
+
/*
|
1597
|
+
* The following process is executed only when there is a `finally`
|
1598
|
+
* block.
|
1599
|
+
*/
|
1600
|
+
|
1601
|
+
const originalReturnedForkContext = context.returnedForkContext;
|
1602
|
+
const originalThrownForkContext = context.thrownForkContext;
|
1603
|
+
|
1604
|
+
// no `return` or `throw` in `try` or `catch` so there's nothing left to do
|
1605
|
+
if (
|
1606
|
+
originalReturnedForkContext.empty &&
|
1607
|
+
originalThrownForkContext.empty
|
1608
|
+
) {
|
1609
|
+
return;
|
1610
|
+
}
|
1611
|
+
|
1612
|
+
/*
|
1613
|
+
* The following process is executed only when there is a `finally`
|
1614
|
+
* block and there was a `return` or `throw` in the `try` or `catch`
|
1615
|
+
* blocks.
|
1616
|
+
*/
|
1617
|
+
|
1618
|
+
// Separate head to normal paths and leaving paths.
|
1619
|
+
const headSegments = this.forkContext.head;
|
1620
|
+
|
1621
|
+
this.forkContext = this.forkContext.upper;
|
1622
|
+
const normalSegments = headSegments.slice(
|
1623
|
+
0,
|
1624
|
+
(headSegments.length / 2) | 0,
|
1625
|
+
);
|
1626
|
+
const leavingSegments = headSegments.slice(
|
1627
|
+
(headSegments.length / 2) | 0,
|
1628
|
+
);
|
1629
|
+
|
1630
|
+
// Forwards the leaving path to upper contexts.
|
1631
|
+
if (!originalReturnedForkContext.empty) {
|
1632
|
+
getReturnContext(this).returnedForkContext.add(leavingSegments);
|
1633
|
+
}
|
1634
|
+
if (!originalThrownForkContext.empty) {
|
1635
|
+
getThrowContext(this).thrownForkContext.add(leavingSegments);
|
1636
|
+
}
|
1637
|
+
|
1638
|
+
// Sets the normal path as the next.
|
1639
|
+
this.forkContext.replaceHead(normalSegments);
|
1640
|
+
|
1641
|
+
/*
|
1642
|
+
* If both paths of the `try` block and the `catch` block are
|
1643
|
+
* unreachable, the next path becomes unreachable as well.
|
1644
|
+
*/
|
1645
|
+
if (!context.lastOfTryIsReachable && !context.lastOfCatchIsReachable) {
|
1646
|
+
this.forkContext.makeUnreachable();
|
1647
|
+
}
|
1648
|
+
}
|
1649
|
+
|
1650
|
+
/**
|
1651
|
+
* Makes a code path segment for a `catch` block.
|
1652
|
+
* @returns {void}
|
1653
|
+
*/
|
1654
|
+
makeCatchBlock() {
|
1655
|
+
const context = this.tryContext;
|
1656
|
+
const forkContext = this.forkContext;
|
1657
|
+
const originalThrownForkContext = context.thrownForkContext;
|
1658
|
+
|
1659
|
+
/*
|
1660
|
+
* We are now in a catch block so we need to update the context
|
1661
|
+
* with that information. This includes creating a new fork
|
1662
|
+
* context in case we encounter any `throw` statements here.
|
1663
|
+
*/
|
1664
|
+
context.position = "catch";
|
1665
|
+
context.thrownForkContext = ForkContext.newEmpty(forkContext);
|
1666
|
+
context.lastOfTryIsReachable = forkContext.reachable;
|
1667
|
+
|
1668
|
+
// Merge the thrown paths from the `try` and `catch` blocks
|
1669
|
+
originalThrownForkContext.add(forkContext.head);
|
1670
|
+
const thrownSegments = originalThrownForkContext.makeNext(0, -1);
|
1671
|
+
|
1672
|
+
// Fork to a bypass and the merged thrown path.
|
1673
|
+
this.pushForkContext();
|
1674
|
+
this.forkBypassPath();
|
1675
|
+
this.forkContext.add(thrownSegments);
|
1676
|
+
}
|
1677
|
+
|
1678
|
+
/**
|
1679
|
+
* Makes a code path segment for a `finally` block.
|
1680
|
+
*
|
1681
|
+
* In the `finally` block, parallel paths are created. The parallel paths
|
1682
|
+
* are used as leaving-paths. The leaving-paths are paths from `return`
|
1683
|
+
* statements and `throw` statements in a `try` block or a `catch` block.
|
1684
|
+
* @returns {void}
|
1685
|
+
*/
|
1686
|
+
makeFinallyBlock() {
|
1687
|
+
const context = this.tryContext;
|
1688
|
+
let forkContext = this.forkContext;
|
1689
|
+
const originalReturnedForkContext = context.returnedForkContext;
|
1690
|
+
const originalThrownForContext = context.thrownForkContext;
|
1691
|
+
const headOfLeavingSegments = forkContext.head;
|
1692
|
+
|
1693
|
+
// Update state.
|
1694
|
+
if (context.position === "catch") {
|
1695
|
+
// Merges two paths from the `try` block and `catch` block.
|
1696
|
+
this.popForkContext();
|
1697
|
+
forkContext = this.forkContext;
|
1698
|
+
|
1699
|
+
context.lastOfCatchIsReachable = forkContext.reachable;
|
1700
|
+
} else {
|
1701
|
+
context.lastOfTryIsReachable = forkContext.reachable;
|
1702
|
+
}
|
1703
|
+
|
1704
|
+
context.position = "finally";
|
1705
|
+
|
1706
|
+
/*
|
1707
|
+
* If there was no `return` or `throw` in either the `try` or `catch`
|
1708
|
+
* blocks, then there's no further code paths to create for `finally`.
|
1709
|
+
*/
|
1710
|
+
if (
|
1711
|
+
originalReturnedForkContext.empty &&
|
1712
|
+
originalThrownForContext.empty
|
1713
|
+
) {
|
1714
|
+
// This path does not leave.
|
1715
|
+
return;
|
1716
|
+
}
|
1717
|
+
|
1718
|
+
/*
|
1719
|
+
* Create a parallel segment from merging returned and thrown.
|
1720
|
+
* This segment will leave at the end of this `finally` block.
|
1721
|
+
*/
|
1722
|
+
const segments = forkContext.makeNext(-1, -1);
|
1723
|
+
|
1724
|
+
for (let i = 0; i < forkContext.count; ++i) {
|
1725
|
+
const prevSegsOfLeavingSegment = [headOfLeavingSegments[i]];
|
1726
|
+
|
1727
|
+
for (
|
1728
|
+
let j = 0;
|
1729
|
+
j < originalReturnedForkContext.segmentsList.length;
|
1730
|
+
++j
|
1731
|
+
) {
|
1732
|
+
prevSegsOfLeavingSegment.push(
|
1733
|
+
originalReturnedForkContext.segmentsList[j][i],
|
1734
|
+
);
|
1735
|
+
}
|
1736
|
+
for (
|
1737
|
+
let j = 0;
|
1738
|
+
j < originalThrownForContext.segmentsList.length;
|
1739
|
+
++j
|
1740
|
+
) {
|
1741
|
+
prevSegsOfLeavingSegment.push(
|
1742
|
+
originalThrownForContext.segmentsList[j][i],
|
1743
|
+
);
|
1744
|
+
}
|
1745
|
+
|
1746
|
+
segments.push(
|
1747
|
+
CodePathSegment.newNext(
|
1748
|
+
this.idGenerator.next(),
|
1749
|
+
prevSegsOfLeavingSegment,
|
1750
|
+
),
|
1751
|
+
);
|
1752
|
+
}
|
1753
|
+
|
1754
|
+
this.pushForkContext(true);
|
1755
|
+
this.forkContext.add(segments);
|
1756
|
+
}
|
1757
|
+
|
1758
|
+
/**
|
1759
|
+
* Makes a code path segment from the first throwable node to the `catch`
|
1760
|
+
* block or the `finally` block.
|
1761
|
+
* @returns {void}
|
1762
|
+
*/
|
1763
|
+
makeFirstThrowablePathInTryBlock() {
|
1764
|
+
const forkContext = this.forkContext;
|
1765
|
+
|
1766
|
+
if (!forkContext.reachable) {
|
1767
|
+
return;
|
1768
|
+
}
|
1769
|
+
|
1770
|
+
const context = getThrowContext(this);
|
1771
|
+
|
1772
|
+
if (
|
1773
|
+
context === this ||
|
1774
|
+
context.position !== "try" ||
|
1775
|
+
!context.thrownForkContext.empty
|
1776
|
+
) {
|
1777
|
+
return;
|
1778
|
+
}
|
1779
|
+
|
1780
|
+
context.thrownForkContext.add(forkContext.head);
|
1781
|
+
forkContext.replaceHead(forkContext.makeNext(-1, -1));
|
1782
|
+
}
|
1783
|
+
|
1784
|
+
//--------------------------------------------------------------------------
|
1785
|
+
// Loop Statements
|
1786
|
+
//--------------------------------------------------------------------------
|
1787
|
+
|
1788
|
+
/**
|
1789
|
+
* Creates a context object of a loop statement and stacks it.
|
1790
|
+
* @param {string} type The type of the node which was triggered. One of
|
1791
|
+
* `WhileStatement`, `DoWhileStatement`, `ForStatement`, `ForInStatement`,
|
1792
|
+
* and `ForStatement`.
|
1793
|
+
* @param {string|null} label A label of the node which was triggered.
|
1794
|
+
* @throws {Error} (Unreachable - unknown type.)
|
1795
|
+
* @returns {void}
|
1796
|
+
*/
|
1797
|
+
pushLoopContext(type, label) {
|
1798
|
+
const forkContext = this.forkContext;
|
1799
|
+
|
1800
|
+
// All loops need a path to account for `break` statements
|
1801
|
+
const breakContext = this.pushBreakContext(true, label);
|
1802
|
+
|
1803
|
+
switch (type) {
|
1804
|
+
case "WhileStatement":
|
1805
|
+
this.pushChoiceContext("loop", false);
|
1806
|
+
this.loopContext = new WhileLoopContext(
|
1807
|
+
this.loopContext,
|
1808
|
+
label,
|
1809
|
+
breakContext,
|
1810
|
+
);
|
1811
|
+
break;
|
1812
|
+
|
1813
|
+
case "DoWhileStatement":
|
1814
|
+
this.pushChoiceContext("loop", false);
|
1815
|
+
this.loopContext = new DoWhileLoopContext(
|
1816
|
+
this.loopContext,
|
1817
|
+
label,
|
1818
|
+
breakContext,
|
1819
|
+
forkContext,
|
1820
|
+
);
|
1821
|
+
break;
|
1822
|
+
|
1823
|
+
case "ForStatement":
|
1824
|
+
this.pushChoiceContext("loop", false);
|
1825
|
+
this.loopContext = new ForLoopContext(
|
1826
|
+
this.loopContext,
|
1827
|
+
label,
|
1828
|
+
breakContext,
|
1829
|
+
);
|
1830
|
+
break;
|
1831
|
+
|
1832
|
+
case "ForInStatement":
|
1833
|
+
this.loopContext = new ForInLoopContext(
|
1834
|
+
this.loopContext,
|
1835
|
+
label,
|
1836
|
+
breakContext,
|
1837
|
+
);
|
1838
|
+
break;
|
1839
|
+
|
1840
|
+
case "ForOfStatement":
|
1841
|
+
this.loopContext = new ForOfLoopContext(
|
1842
|
+
this.loopContext,
|
1843
|
+
label,
|
1844
|
+
breakContext,
|
1845
|
+
);
|
1846
|
+
break;
|
1847
|
+
|
1848
|
+
/* c8 ignore next */
|
1849
|
+
default:
|
1850
|
+
throw new Error(`unknown type: "${type}"`);
|
1851
|
+
}
|
1852
|
+
}
|
1853
|
+
|
1854
|
+
/**
|
1855
|
+
* Pops the last context of a loop statement and finalizes it.
|
1856
|
+
* @throws {Error} (Unreachable - unknown type.)
|
1857
|
+
* @returns {void}
|
1858
|
+
*/
|
1859
|
+
popLoopContext() {
|
1860
|
+
const context = this.loopContext;
|
1861
|
+
|
1862
|
+
this.loopContext = context.upper;
|
1863
|
+
|
1864
|
+
const forkContext = this.forkContext;
|
1865
|
+
const brokenForkContext = this.popBreakContext().brokenForkContext;
|
1866
|
+
|
1867
|
+
// Creates a looped path.
|
1868
|
+
switch (context.type) {
|
1869
|
+
case "WhileStatement":
|
1870
|
+
case "ForStatement":
|
1871
|
+
this.popChoiceContext();
|
1872
|
+
|
1873
|
+
/*
|
1874
|
+
* Creates the path from the end of the loop body up to the
|
1875
|
+
* location where `continue` would jump to.
|
1876
|
+
*/
|
1877
|
+
makeLooped(
|
1878
|
+
this,
|
1879
|
+
forkContext.head,
|
1880
|
+
context.continueDestSegments,
|
1881
|
+
);
|
1882
|
+
break;
|
1883
|
+
|
1884
|
+
case "DoWhileStatement": {
|
1885
|
+
const choiceContext = this.popChoiceContext();
|
1886
|
+
|
1887
|
+
if (!choiceContext.processed) {
|
1888
|
+
choiceContext.trueForkContext.add(forkContext.head);
|
1889
|
+
choiceContext.falseForkContext.add(forkContext.head);
|
1890
|
+
}
|
1891
|
+
|
1892
|
+
/*
|
1893
|
+
* If this isn't a hardcoded `true` condition, then `break`
|
1894
|
+
* should continue down the path as if the condition evaluated
|
1895
|
+
* to false.
|
1896
|
+
*/
|
1897
|
+
if (context.test !== true) {
|
1898
|
+
brokenForkContext.addAll(choiceContext.falseForkContext);
|
1899
|
+
}
|
1900
|
+
|
1901
|
+
/*
|
1902
|
+
* When the condition is true, the loop continues back to the top,
|
1903
|
+
* so create a path from each possible true condition back to the
|
1904
|
+
* top of the loop.
|
1905
|
+
*/
|
1906
|
+
const segmentsList = choiceContext.trueForkContext.segmentsList;
|
1907
|
+
|
1908
|
+
for (let i = 0; i < segmentsList.length; ++i) {
|
1909
|
+
makeLooped(this, segmentsList[i], context.entrySegments);
|
1910
|
+
}
|
1911
|
+
break;
|
1912
|
+
}
|
1913
|
+
|
1914
|
+
case "ForInStatement":
|
1915
|
+
case "ForOfStatement":
|
1916
|
+
brokenForkContext.add(forkContext.head);
|
1917
|
+
|
1918
|
+
/*
|
1919
|
+
* Creates the path from the end of the loop body up to the
|
1920
|
+
* left expression (left of `in` or `of`) of the loop.
|
1921
|
+
*/
|
1922
|
+
makeLooped(this, forkContext.head, context.leftSegments);
|
1923
|
+
break;
|
1924
|
+
|
1925
|
+
/* c8 ignore next */
|
1926
|
+
default:
|
1927
|
+
throw new Error("unreachable");
|
1928
|
+
}
|
1929
|
+
|
1930
|
+
/*
|
1931
|
+
* If there wasn't a `break` statement in the loop, then we're at
|
1932
|
+
* the end of the loop's path, so we make an unreachable segment
|
1933
|
+
* to mark that.
|
1934
|
+
*
|
1935
|
+
* If there was a `break` statement, then we continue on into the
|
1936
|
+
* `brokenForkContext`.
|
1937
|
+
*/
|
1938
|
+
if (brokenForkContext.empty) {
|
1939
|
+
forkContext.replaceHead(forkContext.makeUnreachable(-1, -1));
|
1940
|
+
} else {
|
1941
|
+
forkContext.replaceHead(brokenForkContext.makeNext(0, -1));
|
1942
|
+
}
|
1943
|
+
}
|
1944
|
+
|
1945
|
+
/**
|
1946
|
+
* Makes a code path segment for the test part of a WhileStatement.
|
1947
|
+
* @param {boolean|undefined} test The test value (only when constant).
|
1948
|
+
* @returns {void}
|
1949
|
+
*/
|
1950
|
+
makeWhileTest(test) {
|
1951
|
+
const context = this.loopContext;
|
1952
|
+
const forkContext = this.forkContext;
|
1953
|
+
const testSegments = forkContext.makeNext(0, -1);
|
1954
|
+
|
1955
|
+
// Update state.
|
1956
|
+
context.test = test;
|
1957
|
+
context.continueDestSegments = testSegments;
|
1958
|
+
forkContext.replaceHead(testSegments);
|
1959
|
+
}
|
1960
|
+
|
1961
|
+
/**
|
1962
|
+
* Makes a code path segment for the body part of a WhileStatement.
|
1963
|
+
* @returns {void}
|
1964
|
+
*/
|
1965
|
+
makeWhileBody() {
|
1966
|
+
const context = this.loopContext;
|
1967
|
+
const choiceContext = this.choiceContext;
|
1968
|
+
const forkContext = this.forkContext;
|
1969
|
+
|
1970
|
+
if (!choiceContext.processed) {
|
1971
|
+
choiceContext.trueForkContext.add(forkContext.head);
|
1972
|
+
choiceContext.falseForkContext.add(forkContext.head);
|
1973
|
+
}
|
1974
|
+
|
1975
|
+
/*
|
1976
|
+
* If this isn't a hardcoded `true` condition, then `break`
|
1977
|
+
* should continue down the path as if the condition evaluated
|
1978
|
+
* to false.
|
1979
|
+
*/
|
1980
|
+
if (context.test !== true) {
|
1981
|
+
context.brokenForkContext.addAll(choiceContext.falseForkContext);
|
1982
|
+
}
|
1983
|
+
forkContext.replaceHead(choiceContext.trueForkContext.makeNext(0, -1));
|
1984
|
+
}
|
1985
|
+
|
1986
|
+
/**
|
1987
|
+
* Makes a code path segment for the body part of a DoWhileStatement.
|
1988
|
+
* @returns {void}
|
1989
|
+
*/
|
1990
|
+
makeDoWhileBody() {
|
1991
|
+
const context = this.loopContext;
|
1992
|
+
const forkContext = this.forkContext;
|
1993
|
+
const bodySegments = forkContext.makeNext(-1, -1);
|
1994
|
+
|
1995
|
+
// Update state.
|
1996
|
+
context.entrySegments = bodySegments;
|
1997
|
+
forkContext.replaceHead(bodySegments);
|
1998
|
+
}
|
1999
|
+
|
2000
|
+
/**
|
2001
|
+
* Makes a code path segment for the test part of a DoWhileStatement.
|
2002
|
+
* @param {boolean|undefined} test The test value (only when constant).
|
2003
|
+
* @returns {void}
|
2004
|
+
*/
|
2005
|
+
makeDoWhileTest(test) {
|
2006
|
+
const context = this.loopContext;
|
2007
|
+
const forkContext = this.forkContext;
|
2008
|
+
|
2009
|
+
context.test = test;
|
2010
|
+
|
2011
|
+
/*
|
2012
|
+
* If there is a `continue` statement in the loop then `continueForkContext`
|
2013
|
+
* won't be empty. We wire up the path from `continue` to the loop
|
2014
|
+
* test condition and then continue the traversal in the root fork context.
|
2015
|
+
*/
|
2016
|
+
if (!context.continueForkContext.empty) {
|
2017
|
+
context.continueForkContext.add(forkContext.head);
|
2018
|
+
const testSegments = context.continueForkContext.makeNext(0, -1);
|
2019
|
+
|
2020
|
+
forkContext.replaceHead(testSegments);
|
2021
|
+
}
|
2022
|
+
}
|
2023
|
+
|
2024
|
+
/**
|
2025
|
+
* Makes a code path segment for the test part of a ForStatement.
|
2026
|
+
* @param {boolean|undefined} test The test value (only when constant).
|
2027
|
+
* @returns {void}
|
2028
|
+
*/
|
2029
|
+
makeForTest(test) {
|
2030
|
+
const context = this.loopContext;
|
2031
|
+
const forkContext = this.forkContext;
|
2032
|
+
const endOfInitSegments = forkContext.head;
|
2033
|
+
const testSegments = forkContext.makeNext(-1, -1);
|
2034
|
+
|
2035
|
+
/*
|
2036
|
+
* Update the state.
|
2037
|
+
*
|
2038
|
+
* The `continueDestSegments` are set to `testSegments` because we
|
2039
|
+
* don't yet know if there is an update expression in this loop. So,
|
2040
|
+
* from what we already know at this point, a `continue` statement
|
2041
|
+
* will jump back to the test expression.
|
2042
|
+
*/
|
2043
|
+
context.test = test;
|
2044
|
+
context.endOfInitSegments = endOfInitSegments;
|
2045
|
+
context.continueDestSegments = context.testSegments = testSegments;
|
2046
|
+
forkContext.replaceHead(testSegments);
|
2047
|
+
}
|
2048
|
+
|
2049
|
+
/**
|
2050
|
+
* Makes a code path segment for the update part of a ForStatement.
|
2051
|
+
* @returns {void}
|
2052
|
+
*/
|
2053
|
+
makeForUpdate() {
|
2054
|
+
const context = this.loopContext;
|
2055
|
+
const choiceContext = this.choiceContext;
|
2056
|
+
const forkContext = this.forkContext;
|
2057
|
+
|
2058
|
+
// Make the next paths of the test.
|
2059
|
+
if (context.testSegments) {
|
2060
|
+
finalizeTestSegmentsOfFor(context, choiceContext, forkContext.head);
|
2061
|
+
} else {
|
2062
|
+
context.endOfInitSegments = forkContext.head;
|
2063
|
+
}
|
2064
|
+
|
2065
|
+
/*
|
2066
|
+
* Update the state.
|
2067
|
+
*
|
2068
|
+
* The `continueDestSegments` are now set to `updateSegments` because we
|
2069
|
+
* know there is an update expression in this loop. So, a `continue` statement
|
2070
|
+
* in the loop will jump to the update expression first, and then to any
|
2071
|
+
* test expression the loop might have.
|
2072
|
+
*/
|
2073
|
+
const updateSegments = forkContext.makeDisconnected(-1, -1);
|
2074
|
+
|
2075
|
+
context.continueDestSegments = context.updateSegments = updateSegments;
|
2076
|
+
forkContext.replaceHead(updateSegments);
|
2077
|
+
}
|
2078
|
+
|
2079
|
+
/**
|
2080
|
+
* Makes a code path segment for the body part of a ForStatement.
|
2081
|
+
* @returns {void}
|
2082
|
+
*/
|
2083
|
+
makeForBody() {
|
2084
|
+
const context = this.loopContext;
|
2085
|
+
const choiceContext = this.choiceContext;
|
2086
|
+
const forkContext = this.forkContext;
|
2087
|
+
|
2088
|
+
/*
|
2089
|
+
* Determine what to do based on which part of the `for` loop are present.
|
2090
|
+
* 1. If there is an update expression, then `updateSegments` is not null and
|
2091
|
+
* we need to assign `endOfUpdateSegments`, and if there is a test
|
2092
|
+
* expression, we then need to create the looped path to get back to
|
2093
|
+
* the test condition.
|
2094
|
+
* 2. If there is no update expression but there is a test expression,
|
2095
|
+
* then we only need to update the test segment information.
|
2096
|
+
* 3. If there is no update expression and no test expression, then we
|
2097
|
+
* just save `endOfInitSegments`.
|
2098
|
+
*/
|
2099
|
+
if (context.updateSegments) {
|
2100
|
+
context.endOfUpdateSegments = forkContext.head;
|
2101
|
+
|
2102
|
+
/*
|
2103
|
+
* In a `for` loop that has both an update expression and a test
|
2104
|
+
* condition, execution flows from the test expression into the
|
2105
|
+
* loop body, to the update expression, and then back to the test
|
2106
|
+
* expression to determine if the loop should continue.
|
2107
|
+
*
|
2108
|
+
* To account for that, we need to make a path from the end of the
|
2109
|
+
* update expression to the start of the test expression. This is
|
2110
|
+
* effectively what creates the loop in the code path.
|
2111
|
+
*/
|
2112
|
+
if (context.testSegments) {
|
2113
|
+
makeLooped(
|
2114
|
+
this,
|
2115
|
+
context.endOfUpdateSegments,
|
2116
|
+
context.testSegments,
|
2117
|
+
);
|
2118
|
+
}
|
2119
|
+
} else if (context.testSegments) {
|
2120
|
+
finalizeTestSegmentsOfFor(context, choiceContext, forkContext.head);
|
2121
|
+
} else {
|
2122
|
+
context.endOfInitSegments = forkContext.head;
|
2123
|
+
}
|
2124
|
+
|
2125
|
+
let bodySegments = context.endOfTestSegments;
|
2126
|
+
|
2127
|
+
/*
|
2128
|
+
* If there is a test condition, then there `endOfTestSegments` is also
|
2129
|
+
* the start of the loop body. If there isn't a test condition then
|
2130
|
+
* `bodySegments` will be null and we need to look elsewhere to find
|
2131
|
+
* the start of the body.
|
2132
|
+
*
|
2133
|
+
* The body starts at the end of the init expression and ends at the end
|
2134
|
+
* of the update expression, so we use those locations to determine the
|
2135
|
+
* body segments.
|
2136
|
+
*/
|
2137
|
+
if (!bodySegments) {
|
2138
|
+
const prevForkContext = ForkContext.newEmpty(forkContext);
|
2139
|
+
|
2140
|
+
prevForkContext.add(context.endOfInitSegments);
|
2141
|
+
if (context.endOfUpdateSegments) {
|
2142
|
+
prevForkContext.add(context.endOfUpdateSegments);
|
2143
|
+
}
|
2144
|
+
|
2145
|
+
bodySegments = prevForkContext.makeNext(0, -1);
|
2146
|
+
}
|
2147
|
+
|
2148
|
+
/*
|
2149
|
+
* If there was no test condition and no update expression, then
|
2150
|
+
* `continueDestSegments` will be null. In that case, a
|
2151
|
+
* `continue` should skip directly to the body of the loop.
|
2152
|
+
* Otherwise, we want to keep the current `continueDestSegments`.
|
2153
|
+
*/
|
2154
|
+
context.continueDestSegments =
|
2155
|
+
context.continueDestSegments || bodySegments;
|
2156
|
+
|
2157
|
+
// move pointer to the body
|
2158
|
+
forkContext.replaceHead(bodySegments);
|
2159
|
+
}
|
2160
|
+
|
2161
|
+
/**
|
2162
|
+
* Makes a code path segment for the left part of a ForInStatement and a
|
2163
|
+
* ForOfStatement.
|
2164
|
+
* @returns {void}
|
2165
|
+
*/
|
2166
|
+
makeForInOfLeft() {
|
2167
|
+
const context = this.loopContext;
|
2168
|
+
const forkContext = this.forkContext;
|
2169
|
+
const leftSegments = forkContext.makeDisconnected(-1, -1);
|
2170
|
+
|
2171
|
+
// Update state.
|
2172
|
+
context.prevSegments = forkContext.head;
|
2173
|
+
context.leftSegments = context.continueDestSegments = leftSegments;
|
2174
|
+
forkContext.replaceHead(leftSegments);
|
2175
|
+
}
|
2176
|
+
|
2177
|
+
/**
|
2178
|
+
* Makes a code path segment for the right part of a ForInStatement and a
|
2179
|
+
* ForOfStatement.
|
2180
|
+
* @returns {void}
|
2181
|
+
*/
|
2182
|
+
makeForInOfRight() {
|
2183
|
+
const context = this.loopContext;
|
2184
|
+
const forkContext = this.forkContext;
|
2185
|
+
const temp = ForkContext.newEmpty(forkContext);
|
2186
|
+
|
2187
|
+
temp.add(context.prevSegments);
|
2188
|
+
const rightSegments = temp.makeNext(-1, -1);
|
2189
|
+
|
2190
|
+
// Update state.
|
2191
|
+
context.endOfLeftSegments = forkContext.head;
|
2192
|
+
forkContext.replaceHead(rightSegments);
|
2193
|
+
}
|
2194
|
+
|
2195
|
+
/**
|
2196
|
+
* Makes a code path segment for the body part of a ForInStatement and a
|
2197
|
+
* ForOfStatement.
|
2198
|
+
* @returns {void}
|
2199
|
+
*/
|
2200
|
+
makeForInOfBody() {
|
2201
|
+
const context = this.loopContext;
|
2202
|
+
const forkContext = this.forkContext;
|
2203
|
+
const temp = ForkContext.newEmpty(forkContext);
|
2204
|
+
|
2205
|
+
temp.add(context.endOfLeftSegments);
|
2206
|
+
const bodySegments = temp.makeNext(-1, -1);
|
2207
|
+
|
2208
|
+
// Make a path: `right` -> `left`.
|
2209
|
+
makeLooped(this, forkContext.head, context.leftSegments);
|
2210
|
+
|
2211
|
+
// Update state.
|
2212
|
+
context.brokenForkContext.add(forkContext.head);
|
2213
|
+
forkContext.replaceHead(bodySegments);
|
2214
|
+
}
|
2215
|
+
|
2216
|
+
//--------------------------------------------------------------------------
|
2217
|
+
// Control Statements
|
2218
|
+
//--------------------------------------------------------------------------
|
2219
|
+
|
2220
|
+
/**
|
2221
|
+
* Creates new context in which a `break` statement can be used. This occurs inside of a loop,
|
2222
|
+
* labeled statement, or switch statement.
|
2223
|
+
* @param {boolean} breakable Indicates if we are inside a statement where
|
2224
|
+
* `break` without a label will exit the statement.
|
2225
|
+
* @param {string|null} label The label associated with the statement.
|
2226
|
+
* @returns {BreakContext} The new context.
|
2227
|
+
*/
|
2228
|
+
pushBreakContext(breakable, label) {
|
2229
|
+
this.breakContext = new BreakContext(
|
2230
|
+
this.breakContext,
|
2231
|
+
breakable,
|
2232
|
+
label,
|
2233
|
+
this.forkContext,
|
2234
|
+
);
|
2235
|
+
return this.breakContext;
|
2236
|
+
}
|
2237
|
+
|
2238
|
+
/**
|
2239
|
+
* Removes the top item of the break context stack.
|
2240
|
+
* @returns {Object} The removed context.
|
2241
|
+
*/
|
2242
|
+
popBreakContext() {
|
2243
|
+
const context = this.breakContext;
|
2244
|
+
const forkContext = this.forkContext;
|
2245
|
+
|
2246
|
+
this.breakContext = context.upper;
|
2247
|
+
|
2248
|
+
// Process this context here for other than switches and loops.
|
2249
|
+
if (!context.breakable) {
|
2250
|
+
const brokenForkContext = context.brokenForkContext;
|
2251
|
+
|
2252
|
+
if (!brokenForkContext.empty) {
|
2253
|
+
brokenForkContext.add(forkContext.head);
|
2254
|
+
forkContext.replaceHead(brokenForkContext.makeNext(0, -1));
|
2255
|
+
}
|
2256
|
+
}
|
2257
|
+
|
2258
|
+
return context;
|
2259
|
+
}
|
2260
|
+
|
2261
|
+
/**
|
2262
|
+
* Makes a path for a `break` statement.
|
2263
|
+
*
|
2264
|
+
* It registers the head segment to a context of `break`.
|
2265
|
+
* It makes new unreachable segment, then it set the head with the segment.
|
2266
|
+
* @param {string|null} label A label of the break statement.
|
2267
|
+
* @returns {void}
|
2268
|
+
*/
|
2269
|
+
makeBreak(label) {
|
2270
|
+
const forkContext = this.forkContext;
|
2271
|
+
|
2272
|
+
if (!forkContext.reachable) {
|
2273
|
+
return;
|
2274
|
+
}
|
2275
|
+
|
2276
|
+
const context = getBreakContext(this, label);
|
2277
|
+
|
2278
|
+
if (context) {
|
2279
|
+
context.brokenForkContext.add(forkContext.head);
|
2280
|
+
}
|
2281
|
+
|
2282
|
+
/* c8 ignore next */
|
2283
|
+
forkContext.replaceHead(forkContext.makeUnreachable(-1, -1));
|
2284
|
+
}
|
2285
|
+
|
2286
|
+
/**
|
2287
|
+
* Makes a path for a `continue` statement.
|
2288
|
+
*
|
2289
|
+
* It makes a looping path.
|
2290
|
+
* It makes new unreachable segment, then it set the head with the segment.
|
2291
|
+
* @param {string|null} label A label of the continue statement.
|
2292
|
+
* @returns {void}
|
2293
|
+
*/
|
2294
|
+
makeContinue(label) {
|
2295
|
+
const forkContext = this.forkContext;
|
2296
|
+
|
2297
|
+
if (!forkContext.reachable) {
|
2298
|
+
return;
|
2299
|
+
}
|
2300
|
+
|
2301
|
+
const context = getContinueContext(this, label);
|
2302
|
+
|
2303
|
+
if (context) {
|
2304
|
+
if (context.continueDestSegments) {
|
2305
|
+
makeLooped(
|
2306
|
+
this,
|
2307
|
+
forkContext.head,
|
2308
|
+
context.continueDestSegments,
|
2309
|
+
);
|
2310
|
+
|
2311
|
+
// If the context is a for-in/of loop, this affects a break also.
|
2312
|
+
if (
|
2313
|
+
context.type === "ForInStatement" ||
|
2314
|
+
context.type === "ForOfStatement"
|
2315
|
+
) {
|
2316
|
+
context.brokenForkContext.add(forkContext.head);
|
2317
|
+
}
|
2318
|
+
} else {
|
2319
|
+
context.continueForkContext.add(forkContext.head);
|
2320
|
+
}
|
2321
|
+
}
|
2322
|
+
forkContext.replaceHead(forkContext.makeUnreachable(-1, -1));
|
2323
|
+
}
|
2324
|
+
|
2325
|
+
/**
|
2326
|
+
* Makes a path for a `return` statement.
|
2327
|
+
*
|
2328
|
+
* It registers the head segment to a context of `return`.
|
2329
|
+
* It makes new unreachable segment, then it set the head with the segment.
|
2330
|
+
* @returns {void}
|
2331
|
+
*/
|
2332
|
+
makeReturn() {
|
2333
|
+
const forkContext = this.forkContext;
|
2334
|
+
|
2335
|
+
if (forkContext.reachable) {
|
2336
|
+
getReturnContext(this).returnedForkContext.add(forkContext.head);
|
2337
|
+
forkContext.replaceHead(forkContext.makeUnreachable(-1, -1));
|
2338
|
+
}
|
2339
|
+
}
|
2340
|
+
|
2341
|
+
/**
|
2342
|
+
* Makes a path for a `throw` statement.
|
2343
|
+
*
|
2344
|
+
* It registers the head segment to a context of `throw`.
|
2345
|
+
* It makes new unreachable segment, then it set the head with the segment.
|
2346
|
+
* @returns {void}
|
2347
|
+
*/
|
2348
|
+
makeThrow() {
|
2349
|
+
const forkContext = this.forkContext;
|
2350
|
+
|
2351
|
+
if (forkContext.reachable) {
|
2352
|
+
getThrowContext(this).thrownForkContext.add(forkContext.head);
|
2353
|
+
forkContext.replaceHead(forkContext.makeUnreachable(-1, -1));
|
2354
|
+
}
|
2355
|
+
}
|
2356
|
+
|
2357
|
+
/**
|
2358
|
+
* Makes the final path.
|
2359
|
+
* @returns {void}
|
2360
|
+
*/
|
2361
|
+
makeFinal() {
|
2362
|
+
const segments = this.currentSegments;
|
2363
|
+
|
2364
|
+
if (segments.length > 0 && segments[0].reachable) {
|
2365
|
+
this.returnedForkContext.add(segments);
|
2366
|
+
}
|
2367
|
+
}
|
2346
2368
|
}
|
2347
2369
|
|
2348
2370
|
module.exports = CodePathState;
|