tsc-ts 0.0.3 → 0.0.5
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 +46 -0
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +74 -0
- package/dist/api/library/ast.generated.d.ts +1145 -0
- package/dist/api/library/ast.generated.js +3 -0
- package/dist/api/library/ast.js +5 -0
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -0
- package/dist/api/library/compiler-options.generated.d.ts +108 -0
- package/dist/api/library/compiler-options.generated.js +3 -0
- package/dist/api/library/diagnostics.d.ts +13 -0
- package/dist/api/library/diagnostics.js +50 -0
- package/dist/api/library/disk.d.ts +13 -0
- package/dist/api/library/disk.js +66 -0
- package/dist/api/library/enums.generated.d.ts +891 -0
- package/dist/api/library/enums.generated.js +916 -0
- package/dist/api/library/errors.d.ts +13 -0
- package/dist/api/library/errors.js +24 -0
- package/dist/api/library/host.d.ts +24 -0
- package/dist/api/library/host.js +52 -0
- package/dist/api/library/index.d.ts +14 -0
- package/dist/api/library/index.js +15 -0
- package/dist/api/library/nodes.d.ts +51 -0
- package/dist/api/library/nodes.js +196 -0
- package/dist/api/library/options.d.ts +144 -0
- package/dist/api/library/options.js +308 -0
- package/dist/api/library/parse.d.ts +19 -0
- package/dist/api/library/parse.js +41 -0
- package/dist/api/library/program.d.ts +21 -0
- package/dist/api/library/program.js +234 -0
- package/dist/api/library/symbols.d.ts +8 -0
- package/dist/api/library/symbols.js +11 -0
- package/dist/api/library/types.d.ts +313 -0
- package/dist/api/library/types.js +6 -0
- package/package.json +22 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +1685 -0
- package/src/library/ast.ts +104 -0
- package/src/library/checker.ts +384 -0
- package/src/library/compiler-options.generated.ts +114 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/enums.generated.ts +1024 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +71 -0
- package/src/library/nodes.ts +232 -0
- package/src/library/options.ts +449 -0
- package/src/library/parse.ts +63 -0
- package/src/library/program.ts +293 -0
- package/src/library/symbols.ts +15 -0
- package/src/library/types.ts +359 -0
|
@@ -0,0 +1,2418 @@
|
|
|
1
|
+
// Lowers class fields, private names, static blocks and `accessor` fields: initializers move to
|
|
2
|
+
// the constructor (useDefineForClassFields: false, or targets before ES2022), private members
|
|
3
|
+
// become WeakMaps, WeakSets and hoisted functions, and static `this` and `super` refer to the class.
|
|
4
|
+
import { ArrayLiteralExpression, BinaryExpression, Block, CallExpression, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConstructorDeclaration, ElementAccessExpression, ExportAssignment, ExpressionWithTypeArguments, GetAccessorDeclaration, HeritageClause, Identifier, NodeList, ObjectLiteralExpression, ParameterDeclaration, ParenthesizedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, SetAccessorDeclaration, ShorthandPropertyAssignment, SpreadAssignment, SpreadElement, StringLiteral, TryStatement, NewExpression, ArrowFunction, CatchClause, FunctionExpression, MethodDeclaration, NodeVisitor, VoidExpression, getBody, getParameters, getInitializer, getMembers, getModifiers, getName, } from '../ast.js';
|
|
5
|
+
import { isLeftHandSideExpression } from '../ast-utilities.js';
|
|
6
|
+
import { getNameOfDeclaration, hasStaticModifier, isAssignmentExpression, isAutoAccessorPropertyDeclaration, isClassLike, isDestructuringAssignment, isMethodOrAccessor, isPrivateIdentifierClassElementDeclaration, isStatic, skipParentheses, } from '../binder-utilities.js';
|
|
7
|
+
import { isIdentifierText } from '../scanner.js';
|
|
8
|
+
import { ScriptTarget, getEmitScriptTarget, getUseDefineForClassFields } from '../options.js';
|
|
9
|
+
import { isModifier, isPrologueDirective, isStatement, nodeIsSynthesized } from '../printer/utilities.js';
|
|
10
|
+
import { classHasClassThisAssignment, findSuperStatementIndexPath, getClassMembers, isClassThisAssignmentBlock, } from './class-utilities.js';
|
|
11
|
+
import { AnonymousFunctionFilter, classHasExplicitlyAssignedName, isClassNamedEvaluationHelperBlock, isNamedEvaluation, transformNamedEvaluation, } from './named-evaluation.js';
|
|
12
|
+
import { Transformer } from './transformer.js';
|
|
13
|
+
import { hasDecorators, hasSyntacticModifier, isParameterPropertyDeclaration, isSameNode, skipOuterExpressions, } from './utilities.js';
|
|
14
|
+
import { VisitorBase } from './visitor-base.js';
|
|
15
|
+
/** How a private name is transformed. */
|
|
16
|
+
class PrivateIdentifierInfo {
|
|
17
|
+
kind;
|
|
18
|
+
/** The WeakMap of an instance field, the WeakSet of instance methods and accessors, or the class for statics. */
|
|
19
|
+
brandCheckIdentifier;
|
|
20
|
+
isStatic;
|
|
21
|
+
/** False for reserved names such as `#constructor` and duplicates. */
|
|
22
|
+
isValid;
|
|
23
|
+
/** The `{ value }` holder of a static field. */
|
|
24
|
+
variableName;
|
|
25
|
+
methodName;
|
|
26
|
+
getterName;
|
|
27
|
+
setterName;
|
|
28
|
+
constructor(kind, brandCheckIdentifier, isStatic, isValid) {
|
|
29
|
+
this.kind = kind;
|
|
30
|
+
this.brandCheckIdentifier = brandCheckIdentifier;
|
|
31
|
+
this.isStatic = isStatic;
|
|
32
|
+
this.isValid = isValid;
|
|
33
|
+
this.variableName = undefined;
|
|
34
|
+
this.methodName = undefined;
|
|
35
|
+
this.getterName = undefined;
|
|
36
|
+
this.setterName = undefined;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The private names of a class, by text, and generated private names, by the node they're generated for. */
|
|
40
|
+
class PrivateEnvironment {
|
|
41
|
+
/** Prefixes generated variable names. */
|
|
42
|
+
className;
|
|
43
|
+
/** Brand checks instances for private methods and accessors. */
|
|
44
|
+
weakSetName;
|
|
45
|
+
members;
|
|
46
|
+
generated;
|
|
47
|
+
constructor() {
|
|
48
|
+
this.className = undefined;
|
|
49
|
+
this.weakSetName = undefined;
|
|
50
|
+
this.members = new Map();
|
|
51
|
+
this.generated = new Map();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class ClassData {
|
|
55
|
+
facts;
|
|
56
|
+
/** Brand checks static members and replaces `this` in static initializers. */
|
|
57
|
+
classConstructor;
|
|
58
|
+
classThis;
|
|
59
|
+
/** Replaces `super` in static initializers. */
|
|
60
|
+
superClassReference;
|
|
61
|
+
constructor() {
|
|
62
|
+
this.facts = 0 /* ClassFacts.None */;
|
|
63
|
+
this.classConstructor = undefined;
|
|
64
|
+
this.classThis = undefined;
|
|
65
|
+
this.superClassReference = undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class ClassEnvironment {
|
|
69
|
+
previous;
|
|
70
|
+
data;
|
|
71
|
+
privateEnv;
|
|
72
|
+
constructor(previous) {
|
|
73
|
+
this.previous = previous;
|
|
74
|
+
this.data = undefined;
|
|
75
|
+
this.privateEnv = undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
class ClassMembers {
|
|
79
|
+
members;
|
|
80
|
+
/** An assignment to evaluate before the class, from computed names using `this` or `super`. */
|
|
81
|
+
prologue;
|
|
82
|
+
constructor(members, prologue) {
|
|
83
|
+
this.members = members;
|
|
84
|
+
this.prologue = prologue;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** A receiver read twice: `read`, assigned by `initialize` first when it had to be cached. */
|
|
88
|
+
class CopiableReceiver {
|
|
89
|
+
read;
|
|
90
|
+
initialize;
|
|
91
|
+
constructor(read, initialize) {
|
|
92
|
+
this.read = read;
|
|
93
|
+
this.initialize = initialize;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class CallBinding {
|
|
97
|
+
thisArg;
|
|
98
|
+
target;
|
|
99
|
+
constructor(thisArg, target) {
|
|
100
|
+
this.thisArg = thisArg;
|
|
101
|
+
this.target = target;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** Visits children in one of the transform's modes. */
|
|
105
|
+
class ModeVisitor extends VisitorBase {
|
|
106
|
+
owner;
|
|
107
|
+
mode;
|
|
108
|
+
constructor(owner, mode) {
|
|
109
|
+
super(owner.context);
|
|
110
|
+
this.owner = owner;
|
|
111
|
+
this.mode = mode;
|
|
112
|
+
}
|
|
113
|
+
visit(node) {
|
|
114
|
+
return this.owner.visitInMode(this.mode, node);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const accessorStorageSuffix = '_accessor_storage';
|
|
118
|
+
export class ClassFieldsTransformer extends Transformer {
|
|
119
|
+
options;
|
|
120
|
+
facts;
|
|
121
|
+
resolver;
|
|
122
|
+
legacyDecorators;
|
|
123
|
+
useDefineForClassFields;
|
|
124
|
+
shouldTransformInitializersUsingSet;
|
|
125
|
+
shouldTransformInitializersUsingDefine;
|
|
126
|
+
shouldTransformInitializers;
|
|
127
|
+
shouldTransformPrivateElementsOrClassStaticBlocks;
|
|
128
|
+
shouldTransformAutoAccessors;
|
|
129
|
+
/** Static initializers move out of the class body, so their `this` and `super` must name the class. */
|
|
130
|
+
shouldTransformThisInStaticInitializers;
|
|
131
|
+
shouldTransformPrivateStaticElementsInFile;
|
|
132
|
+
/** Computed name expressions from elided names, to inline at the next execution site. */
|
|
133
|
+
pendingExpressions;
|
|
134
|
+
/** Statements to emit after the current variable statement, for decorated classes. */
|
|
135
|
+
pendingStatements;
|
|
136
|
+
lexicalEnvironment;
|
|
137
|
+
currentClassContainer;
|
|
138
|
+
currentClassElement;
|
|
139
|
+
/** Class declarations to aliases replacing references to the class in its static initializers. */
|
|
140
|
+
classAliases;
|
|
141
|
+
enclosingClassDeclarations;
|
|
142
|
+
inIterationStatement;
|
|
143
|
+
/** Computed property names evaluate in the scope outside the class. */
|
|
144
|
+
insideComputedPropertyName;
|
|
145
|
+
parentNode;
|
|
146
|
+
currentNode;
|
|
147
|
+
modifierMode;
|
|
148
|
+
discarded;
|
|
149
|
+
heritageMode;
|
|
150
|
+
assignmentTargetMode;
|
|
151
|
+
classElementMode;
|
|
152
|
+
accessorResultMode;
|
|
153
|
+
arrayElementMode;
|
|
154
|
+
objectElementMode;
|
|
155
|
+
substitutionMode;
|
|
156
|
+
/** Anonymous classes that named evaluation must name here. */
|
|
157
|
+
classesNeedingNames;
|
|
158
|
+
constructor(context, options, facts, resolver) {
|
|
159
|
+
super(context);
|
|
160
|
+
this.options = options;
|
|
161
|
+
this.facts = facts;
|
|
162
|
+
this.resolver = resolver;
|
|
163
|
+
const target = getEmitScriptTarget(options);
|
|
164
|
+
const useDefine = getUseDefineForClassFields(options);
|
|
165
|
+
this.legacyDecorators = options.experimentalDecorators === true;
|
|
166
|
+
this.useDefineForClassFields = useDefine;
|
|
167
|
+
this.shouldTransformInitializersUsingSet = !useDefine;
|
|
168
|
+
this.shouldTransformInitializersUsingDefine = useDefine && target < ScriptTarget.ES2022;
|
|
169
|
+
this.shouldTransformInitializers =
|
|
170
|
+
this.shouldTransformInitializersUsingSet || this.shouldTransformInitializersUsingDefine;
|
|
171
|
+
this.shouldTransformPrivateElementsOrClassStaticBlocks = target < ScriptTarget.ES2022;
|
|
172
|
+
this.shouldTransformAutoAccessors = target < ScriptTarget.ESNext;
|
|
173
|
+
this.shouldTransformThisInStaticInitializers = target < ScriptTarget.ES2022;
|
|
174
|
+
this.shouldTransformPrivateStaticElementsInFile = false;
|
|
175
|
+
this.pendingExpressions = [];
|
|
176
|
+
this.pendingStatements = [];
|
|
177
|
+
this.lexicalEnvironment = undefined;
|
|
178
|
+
this.currentClassContainer = undefined;
|
|
179
|
+
this.currentClassElement = undefined;
|
|
180
|
+
this.classAliases = new Map();
|
|
181
|
+
this.enclosingClassDeclarations = new Set();
|
|
182
|
+
this.inIterationStatement = false;
|
|
183
|
+
this.insideComputedPropertyName = false;
|
|
184
|
+
this.parentNode = undefined;
|
|
185
|
+
this.currentNode = undefined;
|
|
186
|
+
this.modifierMode = new ModeVisitor(this, 0 /* VisitMode.Modifier */);
|
|
187
|
+
this.discarded = new ModeVisitor(this, 1 /* VisitMode.Discarded */);
|
|
188
|
+
this.heritageMode = new ModeVisitor(this, 2 /* VisitMode.HeritageClause */);
|
|
189
|
+
this.assignmentTargetMode = new ModeVisitor(this, 3 /* VisitMode.AssignmentTarget */);
|
|
190
|
+
this.classElementMode = new ModeVisitor(this, 4 /* VisitMode.ClassElement */);
|
|
191
|
+
this.accessorResultMode = new ModeVisitor(this, 5 /* VisitMode.AccessorFieldResult */);
|
|
192
|
+
this.arrayElementMode = new ModeVisitor(this, 6 /* VisitMode.ArrayAssignmentElement */);
|
|
193
|
+
this.objectElementMode = new ModeVisitor(this, 7 /* VisitMode.ObjectAssignmentElement */);
|
|
194
|
+
this.substitutionMode = new ModeVisitor(this, 8 /* VisitMode.Substitution */);
|
|
195
|
+
this.classesNeedingNames = new ClassesNeedingNames(this);
|
|
196
|
+
}
|
|
197
|
+
visitInMode(mode, node) {
|
|
198
|
+
switch (mode) {
|
|
199
|
+
case 0 /* VisitMode.Modifier */:
|
|
200
|
+
return this.visitModifier(node);
|
|
201
|
+
case 1 /* VisitMode.Discarded */:
|
|
202
|
+
return this.visitDiscardedValue(node);
|
|
203
|
+
case 2 /* VisitMode.HeritageClause */:
|
|
204
|
+
return this.visitHeritageClause(node);
|
|
205
|
+
case 3 /* VisitMode.AssignmentTarget */:
|
|
206
|
+
if (node instanceof ObjectLiteralExpression || node instanceof ArrayLiteralExpression)
|
|
207
|
+
return this.visitAssignmentPattern(node);
|
|
208
|
+
return this.visit(node);
|
|
209
|
+
case 4 /* VisitMode.ClassElement */:
|
|
210
|
+
return this.visitClassElement(node);
|
|
211
|
+
case 5 /* VisitMode.AccessorFieldResult */:
|
|
212
|
+
return this.visitAccessorFieldResult(node);
|
|
213
|
+
case 6 /* VisitMode.ArrayAssignmentElement */:
|
|
214
|
+
return this.visitArrayAssignmentElement(node);
|
|
215
|
+
case 7 /* VisitMode.ObjectAssignmentElement */:
|
|
216
|
+
return this.visitObjectAssignmentElement(node);
|
|
217
|
+
case 8 /* VisitMode.Substitution */:
|
|
218
|
+
return this.visitForSubstitution(node);
|
|
219
|
+
}
|
|
220
|
+
return node;
|
|
221
|
+
}
|
|
222
|
+
/** Whether an auto-accessor, a `#x in` check or a private access needs WeakMaps and WeakSets. */
|
|
223
|
+
requiresBlockScopedVar() {
|
|
224
|
+
const container = this.currentClassContainer;
|
|
225
|
+
return this.inIterationStatement && container !== undefined && container.kind === 232 /* SyntaxKind.ClassExpression */;
|
|
226
|
+
}
|
|
227
|
+
/** Whether a class expression's temporary is block scoped: it's in a loop and has an instance field with a computed name. */
|
|
228
|
+
classExpressionNeedsBlockScopedTemp() {
|
|
229
|
+
if (!this.requiresBlockScopedVar())
|
|
230
|
+
return false;
|
|
231
|
+
const members = membersOf(this.currentClassContainer);
|
|
232
|
+
for (let i = 0; i < members.length; i++) {
|
|
233
|
+
const member = members[i];
|
|
234
|
+
if (member instanceof PropertyDeclaration &&
|
|
235
|
+
!hasStaticModifier(member) &&
|
|
236
|
+
member.name instanceof ComputedPropertyName)
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
addHoisted(name, blockScoped) {
|
|
242
|
+
if (blockScoped)
|
|
243
|
+
this.context.addLexicalDeclaration(name);
|
|
244
|
+
else
|
|
245
|
+
this.context.addVariableDeclaration(name);
|
|
246
|
+
return name;
|
|
247
|
+
}
|
|
248
|
+
visitSourceFile(node) {
|
|
249
|
+
if (node.isDeclarationFile)
|
|
250
|
+
return node;
|
|
251
|
+
const context = this.context;
|
|
252
|
+
this.lexicalEnvironment = undefined;
|
|
253
|
+
this.shouldTransformPrivateStaticElementsInFile =
|
|
254
|
+
(context.getEmitFlags(node) & 8388608 /* EmitFlags.TransformPrivateStaticElements */) !== 0;
|
|
255
|
+
this.classAliases.clear();
|
|
256
|
+
this.enclosingClassDeclarations.clear();
|
|
257
|
+
const visited = this.visitEachChild(node);
|
|
258
|
+
const helpers = context.readEmitHelpers();
|
|
259
|
+
for (let i = 0; i < helpers.length; i++)
|
|
260
|
+
context.addEmitHelper(visited, helpers[i]);
|
|
261
|
+
this.classAliases.clear();
|
|
262
|
+
this.enclosingClassDeclarations.clear();
|
|
263
|
+
return visited;
|
|
264
|
+
}
|
|
265
|
+
visitModifier(node) {
|
|
266
|
+
if (node.kind === 128 /* SyntaxKind.AccessorKeyword */)
|
|
267
|
+
return this.shouldTransformAutoAccessorsInCurrentClass() ? undefined : node;
|
|
268
|
+
return isModifier(node) ? node : undefined;
|
|
269
|
+
}
|
|
270
|
+
/** Substitutes class aliases in subtrees with nothing else to transform, leaving property names alone. */
|
|
271
|
+
visitForSubstitution(node) {
|
|
272
|
+
if (node instanceof Identifier)
|
|
273
|
+
return this.visitIdentifier(node);
|
|
274
|
+
if (node instanceof PropertyAccessExpression && node.name instanceof Identifier)
|
|
275
|
+
return this.visitPropertyAccessExpressionForSubstitution(node);
|
|
276
|
+
return this.substitutionMode.visitEachChild(node);
|
|
277
|
+
}
|
|
278
|
+
visit(node) {
|
|
279
|
+
const grandparent = this.parentNode;
|
|
280
|
+
this.parentNode = this.currentNode;
|
|
281
|
+
this.currentNode = node;
|
|
282
|
+
const result = this.visitWorker(node);
|
|
283
|
+
this.currentNode = this.parentNode;
|
|
284
|
+
this.parentNode = grandparent;
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
visitWorker(node) {
|
|
288
|
+
if (!this.facts.has(node, 131072 /* SubtreeFacts.ContainsClassFields */ | 6144 /* SubtreeFacts.ContainsLexicalThisOrSuper */)) {
|
|
289
|
+
if (this.currentClassContainer !== undefined && this.classAliases.size > 0)
|
|
290
|
+
return this.visitForSubstitution(node);
|
|
291
|
+
return node;
|
|
292
|
+
}
|
|
293
|
+
switch (node.kind) {
|
|
294
|
+
case 307 /* SyntaxKind.SourceFile */:
|
|
295
|
+
return this.visitSourceFile(node);
|
|
296
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
297
|
+
case 232 /* SyntaxKind.ClassExpression */:
|
|
298
|
+
return this.visitClassLike(node);
|
|
299
|
+
case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
|
|
300
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
301
|
+
throw new Error('Class elements are visited in class element mode');
|
|
302
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
303
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
304
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
305
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
306
|
+
return this.visitEachChild(this.transformNamedEvaluationIfNeeded(node, ''));
|
|
307
|
+
case 244 /* SyntaxKind.VariableStatement */:
|
|
308
|
+
return this.visitVariableStatement(node);
|
|
309
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
310
|
+
return this.visitExportAssignment(node);
|
|
311
|
+
case 80 /* SyntaxKind.PrivateIdentifier */:
|
|
312
|
+
return this.visitPrivateIdentifier(node);
|
|
313
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
314
|
+
return this.visitPropertyAccessExpression(node);
|
|
315
|
+
case 213 /* SyntaxKind.ElementAccessExpression */:
|
|
316
|
+
return this.visitElementAccessExpression(node);
|
|
317
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */:
|
|
318
|
+
case 226 /* SyntaxKind.PostfixUnaryExpression */:
|
|
319
|
+
return this.visitPreOrPostfixUnaryExpression(node, false);
|
|
320
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
321
|
+
return this.visitBinaryExpression(node, false);
|
|
322
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
323
|
+
return this.factory.updateParenthesizedExpression(node, this.visitNode(node.expression));
|
|
324
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
325
|
+
return this.visitCallExpression(node);
|
|
326
|
+
case 245 /* SyntaxKind.ExpressionStatement */:
|
|
327
|
+
return this.visitExpressionStatement(node);
|
|
328
|
+
case 216 /* SyntaxKind.TaggedTemplateExpression */:
|
|
329
|
+
return this.visitTaggedTemplateExpression(node);
|
|
330
|
+
case 249 /* SyntaxKind.ForStatement */:
|
|
331
|
+
return this.visitForStatement(node);
|
|
332
|
+
case 250 /* SyntaxKind.ForInStatement */:
|
|
333
|
+
case 251 /* SyntaxKind.ForOfStatement */:
|
|
334
|
+
case 247 /* SyntaxKind.DoStatement */:
|
|
335
|
+
case 248 /* SyntaxKind.WhileStatement */:
|
|
336
|
+
return this.visitInIteration(node, true);
|
|
337
|
+
case 109 /* SyntaxKind.ThisKeyword */:
|
|
338
|
+
return this.visitThisExpression(node);
|
|
339
|
+
case 263 /* SyntaxKind.FunctionDeclaration */:
|
|
340
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
341
|
+
return this.visitFunctionExpressionOrDeclaration(node);
|
|
342
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
343
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
344
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
345
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
346
|
+
return this.visitInClassElement(node);
|
|
347
|
+
}
|
|
348
|
+
return this.visitEachChild(node);
|
|
349
|
+
}
|
|
350
|
+
visitInIteration(node, inIteration) {
|
|
351
|
+
const saved = this.inIterationStatement;
|
|
352
|
+
this.inIterationStatement = inIteration;
|
|
353
|
+
const result = this.visitEachChild(node);
|
|
354
|
+
this.inIterationStatement = saved;
|
|
355
|
+
return result;
|
|
356
|
+
}
|
|
357
|
+
/** Visits the children of a function-like class member with it as the current class element. */
|
|
358
|
+
visitInClassElement(node) {
|
|
359
|
+
const savedIteration = this.inIterationStatement;
|
|
360
|
+
const savedElement = this.currentClassElement;
|
|
361
|
+
this.inIterationStatement = false;
|
|
362
|
+
this.currentClassElement = node;
|
|
363
|
+
const result = this.visitEachChild(node);
|
|
364
|
+
this.currentClassElement = savedElement;
|
|
365
|
+
this.inIterationStatement = savedIteration;
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Functions get their own `this`, unless synthesized from a static member of the current class,
|
|
370
|
+
* as the ES decorators transform does for static private auto-accessors.
|
|
371
|
+
*/
|
|
372
|
+
visitFunctionExpressionOrDeclaration(node) {
|
|
373
|
+
const savedIteration = this.inIterationStatement;
|
|
374
|
+
this.inIterationStatement = false;
|
|
375
|
+
let keepElement = false;
|
|
376
|
+
const container = this.currentClassContainer;
|
|
377
|
+
if (this.currentClassElement !== undefined && container !== undefined) {
|
|
378
|
+
const original = this.context.mostOriginal(node);
|
|
379
|
+
if (original !== node) {
|
|
380
|
+
const members = membersOf(container);
|
|
381
|
+
for (let i = 0; i < members.length; i++)
|
|
382
|
+
if (this.context.mostOriginal(members[i]) === original && isStatic(members[i]))
|
|
383
|
+
keepElement = true;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
const savedElement = this.currentClassElement;
|
|
387
|
+
if (!keepElement)
|
|
388
|
+
this.currentClassElement = undefined;
|
|
389
|
+
const result = this.visitEachChild(node);
|
|
390
|
+
this.currentClassElement = savedElement;
|
|
391
|
+
this.inIterationStatement = savedIteration;
|
|
392
|
+
return result;
|
|
393
|
+
}
|
|
394
|
+
visitDiscardedValue(node) {
|
|
395
|
+
switch (node.kind) {
|
|
396
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */:
|
|
397
|
+
case 226 /* SyntaxKind.PostfixUnaryExpression */:
|
|
398
|
+
return this.visitPreOrPostfixUnaryExpression(node, true);
|
|
399
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
400
|
+
return this.visitBinaryExpression(node, true);
|
|
401
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
402
|
+
return this.factory.updateParenthesizedExpression(node, this.discarded.visitNode(node.expression));
|
|
403
|
+
}
|
|
404
|
+
return this.visit(node);
|
|
405
|
+
}
|
|
406
|
+
visitHeritageClause(node) {
|
|
407
|
+
if (node instanceof HeritageClause)
|
|
408
|
+
return this.heritageMode.visitEachChild(node);
|
|
409
|
+
if (node instanceof ExpressionWithTypeArguments)
|
|
410
|
+
return this.visitExpressionWithTypeArgumentsInHeritageClause(node);
|
|
411
|
+
return this.visit(node);
|
|
412
|
+
}
|
|
413
|
+
visitClassElement(node) {
|
|
414
|
+
switch (node.kind) {
|
|
415
|
+
case 177 /* SyntaxKind.Constructor */: {
|
|
416
|
+
const saved = this.currentClassElement;
|
|
417
|
+
this.currentClassElement = node;
|
|
418
|
+
const container = this.currentClassContainer;
|
|
419
|
+
const result = container !== undefined
|
|
420
|
+
? this.transformConstructor(node, container)
|
|
421
|
+
: this.visitEachChild(node);
|
|
422
|
+
this.currentClassElement = saved;
|
|
423
|
+
return result;
|
|
424
|
+
}
|
|
425
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
426
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
427
|
+
case 175 /* SyntaxKind.MethodDeclaration */: {
|
|
428
|
+
const saved = this.currentClassElement;
|
|
429
|
+
this.currentClassElement = node;
|
|
430
|
+
const result = this.visitMethodOrAccessorDeclaration(node);
|
|
431
|
+
this.currentClassElement = saved;
|
|
432
|
+
return result;
|
|
433
|
+
}
|
|
434
|
+
case 173 /* SyntaxKind.PropertyDeclaration */: {
|
|
435
|
+
const saved = this.currentClassElement;
|
|
436
|
+
this.currentClassElement = node;
|
|
437
|
+
const result = this.visitPropertyDeclaration(node);
|
|
438
|
+
this.currentClassElement = saved;
|
|
439
|
+
return result;
|
|
440
|
+
}
|
|
441
|
+
case 176 /* SyntaxKind.ClassStaticBlockDeclaration */: {
|
|
442
|
+
const saved = this.currentClassElement;
|
|
443
|
+
this.currentClassElement = node;
|
|
444
|
+
const result = this.shouldTransformPrivateElementsOrClassStaticBlocks ? undefined : this.visitEachChild(node);
|
|
445
|
+
this.currentClassElement = saved;
|
|
446
|
+
return result;
|
|
447
|
+
}
|
|
448
|
+
case 168 /* SyntaxKind.ComputedPropertyName */:
|
|
449
|
+
return this.visitComputedPropertyName(node);
|
|
450
|
+
case 241 /* SyntaxKind.SemicolonClassElement */:
|
|
451
|
+
return node;
|
|
452
|
+
}
|
|
453
|
+
if (isModifier(node) || node.kind === 171 /* SyntaxKind.Decorator */)
|
|
454
|
+
return this.visitModifier(node);
|
|
455
|
+
return this.visit(node);
|
|
456
|
+
}
|
|
457
|
+
visitPropertyName(name) {
|
|
458
|
+
if (name instanceof ComputedPropertyName)
|
|
459
|
+
return this.visitComputedPropertyName(name);
|
|
460
|
+
return this.visitNode(name);
|
|
461
|
+
}
|
|
462
|
+
/** Visits the field and accessors an auto-accessor became. */
|
|
463
|
+
visitAccessorFieldResult(node) {
|
|
464
|
+
if (node instanceof PropertyDeclaration)
|
|
465
|
+
return this.transformFieldInitializer(node);
|
|
466
|
+
if (node instanceof GetAccessorDeclaration || node instanceof SetAccessorDeclaration)
|
|
467
|
+
return this.visitClassElement(node);
|
|
468
|
+
throw new Error('Expected a property declaration or accessor');
|
|
469
|
+
}
|
|
470
|
+
/** A reference to a class from its static initializers, replaced with the class alias. */
|
|
471
|
+
visitIdentifier(node) {
|
|
472
|
+
const declaration = this.resolver.getReferencedValueDeclaration(this.mostOriginalIdentifier(node));
|
|
473
|
+
if (declaration === undefined)
|
|
474
|
+
return node;
|
|
475
|
+
const alias = this.classAliases.get(declaration);
|
|
476
|
+
if (alias === undefined || !this.enclosingClassDeclarations.has(declaration))
|
|
477
|
+
return node;
|
|
478
|
+
const clone = this.factory.cloneIdentifier(alias);
|
|
479
|
+
this.context.setSourceMapRange(clone, node.pos, node.end);
|
|
480
|
+
this.context.setCommentRange(clone, node.pos, node.end);
|
|
481
|
+
return clone;
|
|
482
|
+
}
|
|
483
|
+
mostOriginalIdentifier(node) {
|
|
484
|
+
const original = this.context.mostOriginal(node);
|
|
485
|
+
return original instanceof Identifier ? original : node;
|
|
486
|
+
}
|
|
487
|
+
/** An undeclared private name becomes an empty identifier, except as a statement such as `#;`. */
|
|
488
|
+
visitPrivateIdentifier(node) {
|
|
489
|
+
if (!this.shouldTransformPrivateElementsOrClassStaticBlocks)
|
|
490
|
+
return node;
|
|
491
|
+
const parent = this.parentNode;
|
|
492
|
+
if (parent !== undefined && isStatement(parent))
|
|
493
|
+
return node;
|
|
494
|
+
const result = this.factory.createIdentifier('');
|
|
495
|
+
this.context.setOriginal(result, node);
|
|
496
|
+
return result;
|
|
497
|
+
}
|
|
498
|
+
/** `#x in obj` */
|
|
499
|
+
transformPrivateIdentifierInInExpression(node) {
|
|
500
|
+
const info = this.accessPrivateIdentifier(node.left);
|
|
501
|
+
if (info === undefined)
|
|
502
|
+
return this.visitEachChild(node);
|
|
503
|
+
const receiver = this.visitNode(node.right);
|
|
504
|
+
const result = this.factory.createClassPrivateFieldInHelper(info.brandCheckIdentifier, receiver);
|
|
505
|
+
this.context.setOriginal(result, node);
|
|
506
|
+
return result;
|
|
507
|
+
}
|
|
508
|
+
/** An anonymous class whose static members move out of its body, so it can't name itself. */
|
|
509
|
+
isAnonymousClassNeedingAssignedName(node) {
|
|
510
|
+
if (!(node instanceof ClassExpression) || node.name !== undefined)
|
|
511
|
+
return false;
|
|
512
|
+
const statics = staticPropertiesAndClassStaticBlocks(node);
|
|
513
|
+
for (let i = 0; i < statics.length; i++)
|
|
514
|
+
if (isClassNamedEvaluationHelperBlock(this.context, statics[i]))
|
|
515
|
+
return false;
|
|
516
|
+
return this.hasTransformableStatics(node, statics);
|
|
517
|
+
}
|
|
518
|
+
hasTransformableStatics(node, statics) {
|
|
519
|
+
if (!this.shouldTransformPrivateElementsOrClassStaticBlocks && !this.hasTransformPrivateStaticElementsFlag(node))
|
|
520
|
+
return false;
|
|
521
|
+
for (let i = 0; i < statics.length; i++) {
|
|
522
|
+
const member = statics[i];
|
|
523
|
+
if (member.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */ ||
|
|
524
|
+
isPrivateIdentifierClassElementDeclaration(member) ||
|
|
525
|
+
(this.shouldTransformInitializers && isInitializedProperty(member)))
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
/** `node`, naming an anonymous class whose static members move out of its body. */
|
|
531
|
+
transformNamedEvaluationIfNeeded(node, assignedName) {
|
|
532
|
+
if (!isNamedEvaluation(this.context, node, this.classesNeedingNames))
|
|
533
|
+
return node;
|
|
534
|
+
return transformNamedEvaluation(this.context, node, assignedName !== '', assignedName);
|
|
535
|
+
}
|
|
536
|
+
visitVariableStatement(node) {
|
|
537
|
+
const saved = this.pendingStatements;
|
|
538
|
+
this.pendingStatements = [];
|
|
539
|
+
const visited = this.visitEachChild(node);
|
|
540
|
+
const pending = this.pendingStatements;
|
|
541
|
+
this.pendingStatements = saved;
|
|
542
|
+
if (pending.length === 0)
|
|
543
|
+
return visited;
|
|
544
|
+
return this.factory.createSyntaxList([visited].concat(pending));
|
|
545
|
+
}
|
|
546
|
+
visitExportAssignment(node) {
|
|
547
|
+
let updated = node;
|
|
548
|
+
if (isNamedEvaluation(this.context, node, this.classesNeedingNames))
|
|
549
|
+
updated = transformNamedEvaluation(this.context, node, true, node.isExportEquals ? '' : 'default');
|
|
550
|
+
return this.visitEachChild(updated);
|
|
551
|
+
}
|
|
552
|
+
injectPendingExpressions(expression) {
|
|
553
|
+
if (this.pendingExpressions.length === 0)
|
|
554
|
+
return expression;
|
|
555
|
+
const factory = this.factory;
|
|
556
|
+
let result;
|
|
557
|
+
if (expression instanceof ParenthesizedExpression) {
|
|
558
|
+
this.pendingExpressions.push(expression.expression);
|
|
559
|
+
result = factory.updateParenthesizedExpression(expression, factory.inlineExpressions(this.pendingExpressions));
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
this.pendingExpressions.push(expression);
|
|
563
|
+
result = factory.inlineExpressions(this.pendingExpressions);
|
|
564
|
+
}
|
|
565
|
+
this.pendingExpressions = [];
|
|
566
|
+
return result;
|
|
567
|
+
}
|
|
568
|
+
/** Visits a computed name's expression in the lexical environment outside the class. */
|
|
569
|
+
visitInOuterEnvironment(expression) {
|
|
570
|
+
const savedEnvironment = this.lexicalEnvironment;
|
|
571
|
+
const savedInside = this.insideComputedPropertyName;
|
|
572
|
+
this.insideComputedPropertyName = true;
|
|
573
|
+
if (savedEnvironment !== undefined && savedEnvironment.previous !== undefined)
|
|
574
|
+
this.lexicalEnvironment = savedEnvironment.previous;
|
|
575
|
+
const visited = this.visitNode(expression);
|
|
576
|
+
this.lexicalEnvironment = savedEnvironment;
|
|
577
|
+
this.insideComputedPropertyName = savedInside;
|
|
578
|
+
return visited;
|
|
579
|
+
}
|
|
580
|
+
visitComputedPropertyName(node) {
|
|
581
|
+
const expression = this.visitInOuterEnvironment(node.expression);
|
|
582
|
+
return this.factory.updateComputedPropertyName(node, this.injectPendingExpressions(expression));
|
|
583
|
+
}
|
|
584
|
+
shouldTransformClassElementToWeakMap(node) {
|
|
585
|
+
return (this.shouldTransformPrivateElementsOrClassStaticBlocks || this.shouldAlwaysTransformPrivateStaticElements(node));
|
|
586
|
+
}
|
|
587
|
+
shouldAlwaysTransformPrivateStaticElements(node) {
|
|
588
|
+
return hasStaticModifier(node) && this.hasTransformPrivateStaticElementsFlag(node);
|
|
589
|
+
}
|
|
590
|
+
hasTransformPrivateStaticElementsFlag(node) {
|
|
591
|
+
return (this.context.getEmitFlags(node) & 8388608 /* EmitFlags.TransformPrivateStaticElements */) !== 0;
|
|
592
|
+
}
|
|
593
|
+
/** A private method or accessor becomes a hoisted function; the member is removed. */
|
|
594
|
+
visitMethodOrAccessorDeclaration(node) {
|
|
595
|
+
if (!isPrivateIdentifierClassElementDeclaration(node) || !this.shouldTransformClassElementToWeakMap(node))
|
|
596
|
+
return this.classElementMode.visitEachChild(node);
|
|
597
|
+
const info = this.accessPrivateIdentifier(getName(node));
|
|
598
|
+
if (info === undefined)
|
|
599
|
+
throw new Error('Undeclared private name for property declaration.');
|
|
600
|
+
if (!info.isValid)
|
|
601
|
+
return node;
|
|
602
|
+
const functionName = this.getHoistedFunctionName(node, info);
|
|
603
|
+
if (functionName !== undefined) {
|
|
604
|
+
const factory = this.factory;
|
|
605
|
+
const modifiers = this.extractModifiers(getModifiers(node), ~(256 /* ModifierFlags.Static */ | 512 /* ModifierFlags.Accessor */));
|
|
606
|
+
this.context.startVariableEnvironment();
|
|
607
|
+
const saved = this.inIterationStatement;
|
|
608
|
+
this.inIterationStatement = false;
|
|
609
|
+
const body = this.visitFunctionBody(getBody(node));
|
|
610
|
+
const parameters = this.visitNodes(parametersOf(node));
|
|
611
|
+
this.inIterationStatement = saved;
|
|
612
|
+
const asterisk = node instanceof MethodDeclaration ? node.asteriskToken : undefined;
|
|
613
|
+
const fn = factory.created(new FunctionExpression(modifiers, asterisk, functionName, undefined, parameters, undefined, undefined, body));
|
|
614
|
+
this.pendingExpressions.push(factory.createAssignment(functionName, fn));
|
|
615
|
+
}
|
|
616
|
+
return undefined;
|
|
617
|
+
}
|
|
618
|
+
getHoistedFunctionName(node, info) {
|
|
619
|
+
if (info.kind === 1 /* PrivateKind.Method */)
|
|
620
|
+
return info.methodName;
|
|
621
|
+
if (info.kind === 2 /* PrivateKind.Accessor */) {
|
|
622
|
+
if (node.kind === 178 /* SyntaxKind.GetAccessor */)
|
|
623
|
+
return info.getterName;
|
|
624
|
+
if (node.kind === 179 /* SyntaxKind.SetAccessor */)
|
|
625
|
+
return info.setterName;
|
|
626
|
+
}
|
|
627
|
+
return undefined;
|
|
628
|
+
}
|
|
629
|
+
/** `this` in a static initializer of the current class: its classThis or constructor alias. */
|
|
630
|
+
tryGetClassThis() {
|
|
631
|
+
const classThis = this.tryGetClassThisNoContainer();
|
|
632
|
+
if (classThis !== undefined)
|
|
633
|
+
return classThis;
|
|
634
|
+
const container = this.currentClassContainer;
|
|
635
|
+
return container !== undefined ? getName(container) : undefined;
|
|
636
|
+
}
|
|
637
|
+
tryGetClassThisNoContainer() {
|
|
638
|
+
const data = this.getClassData();
|
|
639
|
+
return data.classThis !== undefined ? data.classThis : data.classConstructor;
|
|
640
|
+
}
|
|
641
|
+
/** `accessor x = 1` becomes `#x_accessor_storage = 1`, `get x()` and `set x(value)`. */
|
|
642
|
+
transformAutoAccessor(node) {
|
|
643
|
+
const factory = this.factory;
|
|
644
|
+
const context = this.context;
|
|
645
|
+
const commentPos = context.commentPos(node);
|
|
646
|
+
const commentEnd = context.commentEnd(node);
|
|
647
|
+
const sourceMapPos = context.sourceMapPos(node);
|
|
648
|
+
const sourceMapEnd = context.sourceMapEnd(node);
|
|
649
|
+
// The getter and setter share one evaluation of a computed name.
|
|
650
|
+
const name = node.name;
|
|
651
|
+
let getterName = name;
|
|
652
|
+
let setterName = name;
|
|
653
|
+
if (name instanceof ComputedPropertyName && !isSimpleInlineableExpression(name.expression)) {
|
|
654
|
+
const cacheAssignment = findComputedPropertyNameCacheAssignment(name);
|
|
655
|
+
if (cacheAssignment !== undefined) {
|
|
656
|
+
getterName = factory.updateComputedPropertyName(name, this.visitNode(name.expression));
|
|
657
|
+
setterName = factory.updateComputedPropertyName(name, cacheAssignment.left);
|
|
658
|
+
}
|
|
659
|
+
else {
|
|
660
|
+
const temp = factory.createTempVariable(0);
|
|
661
|
+
context.setSourceMapRange(temp, name.expression.pos, name.expression.end);
|
|
662
|
+
context.addVariableDeclaration(temp);
|
|
663
|
+
const assignment = factory.createAssignment(temp, this.visitNode(name.expression));
|
|
664
|
+
context.setSourceMapRange(assignment, name.expression.pos, name.expression.end);
|
|
665
|
+
getterName = factory.updateComputedPropertyName(name, assignment);
|
|
666
|
+
setterName = factory.updateComputedPropertyName(name, temp);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
const modifiers = this.modifierMode.visitModifiers(node.modifiers);
|
|
670
|
+
const backingField = factory.updatePropertyDeclaration(node, modifiers, factory.createGeneratedPrivateNameForNode(node.name, '', accessorStorageSuffix), undefined, undefined, node.initializer);
|
|
671
|
+
context.setOriginal(backingField, node);
|
|
672
|
+
context.addEmitFlags(backingField, 384 /* EmitFlags.NoComments */);
|
|
673
|
+
context.setSourceMapRange(backingField, sourceMapPos, sourceMapEnd);
|
|
674
|
+
let receiver = undefined;
|
|
675
|
+
if (isStatic(node))
|
|
676
|
+
receiver = this.tryGetClassThis();
|
|
677
|
+
if (receiver === undefined)
|
|
678
|
+
receiver = factory.createThisExpression();
|
|
679
|
+
const getter = this.createAccessorPropertyGetRedirector(node, modifiers, getterName, receiver);
|
|
680
|
+
context.setOriginal(getter, node);
|
|
681
|
+
context.setCommentRange(getter, commentPos, commentEnd);
|
|
682
|
+
context.setSourceMapRange(getter, sourceMapPos, sourceMapEnd);
|
|
683
|
+
// Fresh modifiers, so comments aren't duplicated.
|
|
684
|
+
const setterModifiers = modifiers !== undefined ? factory.createModifiersFromFlags(modifiers.modifierFlags) : undefined;
|
|
685
|
+
const setter = this.createAccessorPropertySetRedirector(node, setterModifiers, setterName, receiver);
|
|
686
|
+
context.setOriginal(setter, node);
|
|
687
|
+
context.addEmitFlags(setter, 384 /* EmitFlags.NoComments */);
|
|
688
|
+
context.setSourceMapRange(setter, sourceMapPos, sourceMapEnd);
|
|
689
|
+
return factory.createSyntaxList(this.accessorResultMode.visitArray([backingField, getter, setter]));
|
|
690
|
+
}
|
|
691
|
+
transformPrivateFieldInitializer(node) {
|
|
692
|
+
const factory = this.factory;
|
|
693
|
+
if (this.shouldTransformClassElementToWeakMap(node)) {
|
|
694
|
+
// Fields become WeakMaps: the declaration goes.
|
|
695
|
+
const info = this.accessPrivateIdentifier(node.name);
|
|
696
|
+
if (info === undefined)
|
|
697
|
+
throw new Error('Undeclared private name for property declaration.');
|
|
698
|
+
if (!info.isValid)
|
|
699
|
+
return node;
|
|
700
|
+
// A static field of a class whose static blocks stay becomes a static block.
|
|
701
|
+
if (info.isStatic && !this.shouldTransformPrivateElementsOrClassStaticBlocks) {
|
|
702
|
+
const statement = this.transformPropertyOrClassStaticBlock(node, factory.createThisExpression());
|
|
703
|
+
if (statement !== undefined)
|
|
704
|
+
return factory.created(new ClassStaticBlockDeclaration(undefined, factory.createBlock([statement], true)));
|
|
705
|
+
}
|
|
706
|
+
return undefined;
|
|
707
|
+
}
|
|
708
|
+
if (this.shouldTransformInitializersUsingSet &&
|
|
709
|
+
!hasStaticModifier(node) &&
|
|
710
|
+
(this.currentClassFacts() & 16 /* ClassFacts.WillHoistInitializersToConstructor */) !== 0)
|
|
711
|
+
return factory.updatePropertyDeclaration(node, this.visitModifiers(node.modifiers), node.name, undefined, undefined, undefined);
|
|
712
|
+
const named = this.transformNamedEvaluationIfNeeded(node, '');
|
|
713
|
+
return factory.updatePropertyDeclaration(named, this.modifierMode.visitModifiers(named.modifiers), this.visitPropertyName(named.name), undefined, undefined, this.visitNode(named.initializer));
|
|
714
|
+
}
|
|
715
|
+
transformPublicFieldInitializer(node) {
|
|
716
|
+
const factory = this.factory;
|
|
717
|
+
if (this.shouldTransformInitializers && !isAutoAccessorPropertyDeclaration(node)) {
|
|
718
|
+
// The field goes; its initializer moves to the constructor. A computed name is still evaluated.
|
|
719
|
+
const expression = this.getPropertyNameExpressionIfNeeded(node.name, node.initializer !== undefined || this.useDefineForClassFields);
|
|
720
|
+
if (expression !== undefined)
|
|
721
|
+
flattenCommaList(expression, this.pendingExpressions);
|
|
722
|
+
// With static blocks kept, a static initializer runs in a static block, where `this` is the class.
|
|
723
|
+
if (isStatic(node) && !this.shouldTransformPrivateElementsOrClassStaticBlocks) {
|
|
724
|
+
const statement = this.transformPropertyOrClassStaticBlock(node, factory.createThisExpression());
|
|
725
|
+
if (statement !== undefined) {
|
|
726
|
+
const block = factory.created(new ClassStaticBlockDeclaration(undefined, factory.createBlock([statement], false)));
|
|
727
|
+
this.context.setOriginal(block, node);
|
|
728
|
+
this.context.setCommentRange(block, node.pos, node.end);
|
|
729
|
+
this.context.addEmitFlags(statement, 384 /* EmitFlags.NoComments */);
|
|
730
|
+
return block;
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
return undefined;
|
|
734
|
+
}
|
|
735
|
+
return factory.updatePropertyDeclaration(node, this.modifierMode.visitModifiers(node.modifiers), this.visitPropertyName(node.name), undefined, undefined, this.visitNode(node.initializer));
|
|
736
|
+
}
|
|
737
|
+
transformFieldInitializer(node) {
|
|
738
|
+
if (isPrivateIdentifierClassElementDeclaration(node))
|
|
739
|
+
return this.transformPrivateFieldInitializer(node);
|
|
740
|
+
return this.transformPublicFieldInitializer(node);
|
|
741
|
+
}
|
|
742
|
+
shouldTransformAutoAccessorsInCurrentClass() {
|
|
743
|
+
if (this.shouldTransformAutoAccessors)
|
|
744
|
+
return true;
|
|
745
|
+
// At ESNext with useDefineForClassFields: false, only when initializers move to the constructor.
|
|
746
|
+
return (this.currentClassFacts() & 16 /* ClassFacts.WillHoistInitializersToConstructor */) !== 0;
|
|
747
|
+
}
|
|
748
|
+
currentClassFacts() {
|
|
749
|
+
const environment = this.lexicalEnvironment;
|
|
750
|
+
return environment !== undefined && environment.data !== undefined ? environment.data.facts : 0 /* ClassFacts.None */;
|
|
751
|
+
}
|
|
752
|
+
visitPropertyDeclaration(node) {
|
|
753
|
+
if (isAutoAccessorPropertyDeclaration(node) &&
|
|
754
|
+
(this.shouldTransformAutoAccessorsInCurrentClass() || this.shouldAlwaysTransformPrivateStaticElements(node)))
|
|
755
|
+
return this.transformAutoAccessor(node);
|
|
756
|
+
return this.transformFieldInitializer(node);
|
|
757
|
+
}
|
|
758
|
+
createPrivateIdentifierAccess(info, receiver) {
|
|
759
|
+
return this.createPrivateIdentifierAccessHelper(info, this.visitNode(receiver));
|
|
760
|
+
}
|
|
761
|
+
createPrivateIdentifierAccessHelper(info, receiver) {
|
|
762
|
+
this.context.setCommentRange(receiver, -1, receiver.end);
|
|
763
|
+
const state = info.brandCheckIdentifier;
|
|
764
|
+
switch (info.kind) {
|
|
765
|
+
case 2 /* PrivateKind.Accessor */:
|
|
766
|
+
return this.factory.createClassPrivateFieldGetHelper(receiver, state, 'a', info.getterName);
|
|
767
|
+
case 1 /* PrivateKind.Method */:
|
|
768
|
+
return this.factory.createClassPrivateFieldGetHelper(receiver, state, 'm', info.methodName);
|
|
769
|
+
case 0 /* PrivateKind.Field */:
|
|
770
|
+
return this.factory.createClassPrivateFieldGetHelper(receiver, state, 'f', info.isStatic ? info.variableName : undefined);
|
|
771
|
+
}
|
|
772
|
+
throw new Error('Access helpers should not be created for untransformed private elements');
|
|
773
|
+
}
|
|
774
|
+
/** `super.x` in a static initializer, with the class and its base available. */
|
|
775
|
+
staticSuperData(node) {
|
|
776
|
+
const element = this.currentClassElement;
|
|
777
|
+
const environment = this.lexicalEnvironment;
|
|
778
|
+
if (!this.shouldTransformThisInStaticInitializers ||
|
|
779
|
+
element === undefined ||
|
|
780
|
+
!isSuperProperty(node) ||
|
|
781
|
+
!isStaticPropertyDeclarationOrClassStaticBlock(element) ||
|
|
782
|
+
environment === undefined)
|
|
783
|
+
return undefined;
|
|
784
|
+
return environment.data;
|
|
785
|
+
}
|
|
786
|
+
visitPropertyAccessExpression(node) {
|
|
787
|
+
const factory = this.factory;
|
|
788
|
+
if (node.name instanceof PrivateIdentifier) {
|
|
789
|
+
const info = this.accessPrivateIdentifier(node.name);
|
|
790
|
+
if (info !== undefined) {
|
|
791
|
+
const result = this.createPrivateIdentifierAccess(info, node.expression);
|
|
792
|
+
this.context.setOriginal(result, node);
|
|
793
|
+
result.pos = node.pos;
|
|
794
|
+
result.end = node.end;
|
|
795
|
+
return result;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
const data = node.name instanceof Identifier ? this.staticSuperData(node) : undefined;
|
|
799
|
+
if (data !== undefined) {
|
|
800
|
+
if ((data.facts & 1 /* ClassFacts.ClassWasDecorated */) !== 0)
|
|
801
|
+
return this.visitInvalidSuperProperty(node);
|
|
802
|
+
if (data.classConstructor !== undefined && data.superClassReference !== undefined) {
|
|
803
|
+
// `super.x` becomes `Reflect.get(_baseTemp, "x", _classTemp)`.
|
|
804
|
+
const superProperty = factory.createReflectGetCall(data.superClassReference, factory.createStringLiteralFromNode(node.name), data.classConstructor);
|
|
805
|
+
this.context.setOriginal(superProperty, node.expression);
|
|
806
|
+
superProperty.pos = node.expression.pos;
|
|
807
|
+
superProperty.end = node.expression.end;
|
|
808
|
+
return superProperty;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
// Property names are not references and are never substituted.
|
|
812
|
+
if (node.name instanceof Identifier)
|
|
813
|
+
return this.visitPropertyAccessExpressionForSubstitution(node);
|
|
814
|
+
return this.visitEachChild(node);
|
|
815
|
+
}
|
|
816
|
+
visitPropertyAccessExpressionForSubstitution(node) {
|
|
817
|
+
const expression = this.visitNode(node.expression);
|
|
818
|
+
if (expression === node.expression)
|
|
819
|
+
return node;
|
|
820
|
+
return this.factory.updatePropertyAccessExpression(node, expression, node.questionDotToken, node.name, node.flags);
|
|
821
|
+
}
|
|
822
|
+
visitElementAccessExpression(node) {
|
|
823
|
+
const data = this.staticSuperData(node);
|
|
824
|
+
if (data !== undefined) {
|
|
825
|
+
if ((data.facts & 1 /* ClassFacts.ClassWasDecorated */) !== 0)
|
|
826
|
+
return this.visitInvalidSuperProperty(node);
|
|
827
|
+
if (data.classConstructor !== undefined && data.superClassReference !== undefined) {
|
|
828
|
+
// `super[x]` becomes `Reflect.get(_baseTemp, x, _classTemp)`.
|
|
829
|
+
const superProperty = this.factory.createReflectGetCall(data.superClassReference, this.visitNode(node.argumentExpression), data.classConstructor);
|
|
830
|
+
this.context.setOriginal(superProperty, node.expression);
|
|
831
|
+
superProperty.pos = node.expression.pos;
|
|
832
|
+
superProperty.end = node.expression.end;
|
|
833
|
+
return superProperty;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
return this.visitEachChild(node);
|
|
837
|
+
}
|
|
838
|
+
visitPreOrPostfixUnaryExpression(node, discarded) {
|
|
839
|
+
const factory = this.factory;
|
|
840
|
+
const context = this.context;
|
|
841
|
+
const prefix = node instanceof PrefixUnaryExpression;
|
|
842
|
+
const operator = prefix ? node.operator : node.operator;
|
|
843
|
+
const operand = prefix ? node.operand : node.operand;
|
|
844
|
+
if (operator !== 45 /* SyntaxKind.PlusPlusToken */ && operator !== 46 /* SyntaxKind.MinusMinusToken */)
|
|
845
|
+
return this.visitEachChild(node);
|
|
846
|
+
const target = skipParentheses(operand);
|
|
847
|
+
if (target instanceof PropertyAccessExpression && target.name instanceof PrivateIdentifier) {
|
|
848
|
+
const info = this.accessPrivateIdentifier(target.name);
|
|
849
|
+
if (info === undefined)
|
|
850
|
+
return this.visitEachChild(node);
|
|
851
|
+
const receiver = this.createCopiableReceiver(this.visitNode(target.expression));
|
|
852
|
+
let expression = this.createPrivateIdentifierAccessHelper(info, receiver.read);
|
|
853
|
+
let temp = undefined;
|
|
854
|
+
if (!prefix && !discarded)
|
|
855
|
+
temp = context.addVariableDeclaration(factory.createTempVariable(0));
|
|
856
|
+
expression = this.expandIncrementOrDecrement(node, operator, operand, expression, temp);
|
|
857
|
+
expression = this.createPrivateIdentifierAssignment(info, receiver.initialize !== undefined ? receiver.initialize : receiver.read, expression, 63 /* SyntaxKind.EqualsToken */);
|
|
858
|
+
context.setOriginal(expression, node);
|
|
859
|
+
expression.pos = node.pos;
|
|
860
|
+
expression.end = node.end;
|
|
861
|
+
if (temp !== undefined)
|
|
862
|
+
expression = this.withRange(factory.createCommaExpression(expression, temp), node);
|
|
863
|
+
return expression;
|
|
864
|
+
}
|
|
865
|
+
const data = this.staticSuperData(target);
|
|
866
|
+
if (data === undefined)
|
|
867
|
+
return this.visitEachChild(node);
|
|
868
|
+
if ((data.facts & 1 /* ClassFacts.ClassWasDecorated */) !== 0) {
|
|
869
|
+
const visited = this.visitInvalidSuperProperty(target);
|
|
870
|
+
if (prefix)
|
|
871
|
+
return factory.updatePrefixUnaryExpression(node, operator, visited);
|
|
872
|
+
return factory.updatePostfixUnaryExpression(node, visited, operator);
|
|
873
|
+
}
|
|
874
|
+
if (data.classConstructor === undefined || data.superClassReference === undefined)
|
|
875
|
+
return this.visitEachChild(node);
|
|
876
|
+
// `++super.a` becomes `(Reflect.set(_baseTemp, "a", (_a = Reflect.get(_baseTemp, "a", _classTemp), _b = ++_a), _classTemp), _b)`.
|
|
877
|
+
let getterName = undefined;
|
|
878
|
+
let setterName = undefined;
|
|
879
|
+
if (target instanceof PropertyAccessExpression) {
|
|
880
|
+
if (target.name instanceof Identifier) {
|
|
881
|
+
getterName = factory.createStringLiteralFromNode(target.name);
|
|
882
|
+
setterName = getterName;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
else if (target instanceof ElementAccessExpression) {
|
|
886
|
+
if (isSimpleInlineableExpression(target.argumentExpression)) {
|
|
887
|
+
getterName = target.argumentExpression;
|
|
888
|
+
setterName = getterName;
|
|
889
|
+
}
|
|
890
|
+
else {
|
|
891
|
+
const temp = context.addVariableDeclaration(factory.createTempVariable(0));
|
|
892
|
+
getterName = temp;
|
|
893
|
+
setterName = factory.createAssignment(temp, this.visitNode(target.argumentExpression));
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
if (getterName === undefined || setterName === undefined)
|
|
897
|
+
return this.visitEachChild(node);
|
|
898
|
+
let expression = this.withRange(factory.createReflectGetCall(data.superClassReference, getterName, data.classConstructor), target);
|
|
899
|
+
let temp = undefined;
|
|
900
|
+
if (!discarded)
|
|
901
|
+
temp = context.addVariableDeclaration(factory.createTempVariable(0));
|
|
902
|
+
expression = this.expandIncrementOrDecrement(node, operator, operand, expression, temp);
|
|
903
|
+
expression = factory.createReflectSetCall(data.superClassReference, setterName, expression, data.classConstructor);
|
|
904
|
+
context.setOriginal(expression, node);
|
|
905
|
+
this.withRange(expression, node);
|
|
906
|
+
if (temp !== undefined)
|
|
907
|
+
expression = this.withRange(factory.createCommaExpression(expression, temp), node);
|
|
908
|
+
return expression;
|
|
909
|
+
}
|
|
910
|
+
withRange(node, range) {
|
|
911
|
+
node.pos = range.pos;
|
|
912
|
+
node.end = range.end;
|
|
913
|
+
return node;
|
|
914
|
+
}
|
|
915
|
+
/** `(_a = expression, ++_a)`, or `(_a = expression, result = _a++, _a)` for postfix operators. */
|
|
916
|
+
expandIncrementOrDecrement(node, operator, operand, expression, result) {
|
|
917
|
+
const factory = this.factory;
|
|
918
|
+
const temp = this.context.addVariableDeclaration(factory.createTempVariable(0));
|
|
919
|
+
let value = this.withRange(factory.createAssignment(temp, expression), operand);
|
|
920
|
+
let operation = node instanceof PrefixUnaryExpression
|
|
921
|
+
? factory.createPrefixUnaryExpression(operator, temp)
|
|
922
|
+
: factory.created(new PostfixUnaryExpression(temp, operator));
|
|
923
|
+
this.withRange(operation, node);
|
|
924
|
+
if (result !== undefined)
|
|
925
|
+
operation = this.withRange(factory.createAssignment(result, operation), node);
|
|
926
|
+
value = this.withRange(factory.createCommaExpression(value, operation), node);
|
|
927
|
+
if (node instanceof PostfixUnaryExpression)
|
|
928
|
+
value = this.withRange(factory.createCommaExpression(value, temp), node);
|
|
929
|
+
return value;
|
|
930
|
+
}
|
|
931
|
+
visitForStatement(node) {
|
|
932
|
+
const initializer = this.discarded.visitNode(node.initializer);
|
|
933
|
+
const condition = this.visitNode(node.condition);
|
|
934
|
+
const incrementor = this.discarded.visitNode(node.incrementor);
|
|
935
|
+
const saved = this.inIterationStatement;
|
|
936
|
+
this.inIterationStatement = true;
|
|
937
|
+
const body = this.visitIterationBody(node.statement);
|
|
938
|
+
this.inIterationStatement = saved;
|
|
939
|
+
return this.factory.updateForStatement(node, initializer, condition, incrementor, body);
|
|
940
|
+
}
|
|
941
|
+
visitExpressionStatement(node) {
|
|
942
|
+
// A private name as a statement (`#;`) stays so that it fails at runtime.
|
|
943
|
+
if (node.expression instanceof PrivateIdentifier && this.shouldTransformPrivateElementsOrClassStaticBlocks)
|
|
944
|
+
return node;
|
|
945
|
+
return this.factory.updateExpressionStatement(node, this.discarded.visitNode(node.expression));
|
|
946
|
+
}
|
|
947
|
+
createCopiableReceiver(receiver) {
|
|
948
|
+
const clone = nodeIsSynthesized(receiver) ? receiver : this.shallowClone(receiver);
|
|
949
|
+
if (isSimpleInlineableExpression(receiver))
|
|
950
|
+
return new CopiableReceiver(clone, undefined);
|
|
951
|
+
const read = this.context.addVariableDeclaration(this.factory.createTempVariable(0));
|
|
952
|
+
return new CopiableReceiver(read, this.factory.createAssignment(read, clone));
|
|
953
|
+
}
|
|
954
|
+
/** A copy of `node` sharing its children, which keep generated names. */
|
|
955
|
+
shallowClone(node) {
|
|
956
|
+
const factory = this.factory;
|
|
957
|
+
if (node instanceof Identifier)
|
|
958
|
+
return factory.cloneIdentifier(node);
|
|
959
|
+
if (node instanceof PropertyAccessExpression)
|
|
960
|
+
return factory.cloneNode(node, new PropertyAccessExpression(node.expression, node.questionDotToken, node.name, node.flags));
|
|
961
|
+
if (node instanceof ElementAccessExpression)
|
|
962
|
+
return factory.cloneNode(node, new ElementAccessExpression(node.expression, node.questionDotToken, node.argumentExpression, node.flags));
|
|
963
|
+
if (node instanceof ParenthesizedExpression)
|
|
964
|
+
return factory.cloneNode(node, new ParenthesizedExpression(node.expression));
|
|
965
|
+
if (node instanceof CallExpression)
|
|
966
|
+
return factory.cloneNode(node, new CallExpression(node.expression, node.questionDotToken, node.typeArguments, node.arguments, node.flags));
|
|
967
|
+
return factory.cloneNode(node, node.deepClone());
|
|
968
|
+
}
|
|
969
|
+
visitCallExpression(node) {
|
|
970
|
+
const factory = this.factory;
|
|
971
|
+
const callee = node.expression;
|
|
972
|
+
if (callee instanceof PropertyAccessExpression &&
|
|
973
|
+
callee.name instanceof PrivateIdentifier &&
|
|
974
|
+
this.accessPrivateIdentifier(callee.name) !== undefined) {
|
|
975
|
+
// `obj.#x()` binds `this`: `__classPrivateFieldGet(obj, _C_instances, "m", _C_x).call(obj)`.
|
|
976
|
+
const binding = this.createCallBinding(callee);
|
|
977
|
+
const target = this.visitNode(binding.target);
|
|
978
|
+
const args = [this.visitNode(binding.thisArg)];
|
|
979
|
+
const visitedArgs = this.visitNodes(node.arguments).nodes;
|
|
980
|
+
for (let i = 0; i < visitedArgs.length; i++)
|
|
981
|
+
args.push(visitedArgs[i]);
|
|
982
|
+
const optional = (node.flags & 32 /* NodeFlags.OptionalChain */) !== 0;
|
|
983
|
+
const call = factory.created(new PropertyAccessExpression(target, optional ? node.questionDotToken : undefined, factory.createIdentifier('call'), optional ? 32 /* NodeFlags.OptionalChain */ : 0 /* NodeFlags.None */));
|
|
984
|
+
return factory.updateCallExpression(node, call, undefined, undefined, factory.createNodeList(args), node.flags);
|
|
985
|
+
}
|
|
986
|
+
const data = this.staticSuperData(callee);
|
|
987
|
+
if (data !== undefined && data.classConstructor !== undefined) {
|
|
988
|
+
// `super.f(...)` becomes `Reflect.get(_baseTemp, "f", _classTemp).call(_classTemp, ...)`.
|
|
989
|
+
const invocation = factory.createFunctionCallCall(this.visitNode(callee), data.classConstructor, this.visitNodes(node.arguments).nodes);
|
|
990
|
+
this.context.setOriginal(invocation, node);
|
|
991
|
+
return this.withRange(invocation, node);
|
|
992
|
+
}
|
|
993
|
+
return this.visitEachChild(node);
|
|
994
|
+
}
|
|
995
|
+
visitTaggedTemplateExpression(node) {
|
|
996
|
+
const factory = this.factory;
|
|
997
|
+
const tag = node.tag;
|
|
998
|
+
if (tag instanceof PropertyAccessExpression &&
|
|
999
|
+
tag.name instanceof PrivateIdentifier &&
|
|
1000
|
+
this.accessPrivateIdentifier(tag.name) !== undefined) {
|
|
1001
|
+
// A private tag binds `this` with `.bind`.
|
|
1002
|
+
const binding = this.createCallBinding(tag);
|
|
1003
|
+
const bound = factory.createCallExpression(factory.createPropertyAccessExpression(this.visitNode(binding.target), factory.createIdentifier('bind')), [this.visitNode(binding.thisArg)]);
|
|
1004
|
+
return factory.updateTaggedTemplateExpression(node, bound, undefined, undefined, this.visitNode(node.template), node.flags);
|
|
1005
|
+
}
|
|
1006
|
+
const data = this.staticSuperData(tag);
|
|
1007
|
+
if (data !== undefined && data.classConstructor !== undefined) {
|
|
1008
|
+
// `` super.f`x` `` becomes `` Reflect.get(_baseTemp, "f", _classTemp).bind(_classTemp)`x` ``.
|
|
1009
|
+
const invocation = factory.createFunctionBindCall(this.visitNode(tag), data.classConstructor, []);
|
|
1010
|
+
this.context.setOriginal(invocation, node);
|
|
1011
|
+
this.withRange(invocation, node);
|
|
1012
|
+
return factory.updateTaggedTemplateExpression(node, invocation, undefined, undefined, this.visitNode(node.template), node.flags);
|
|
1013
|
+
}
|
|
1014
|
+
return this.visitEachChild(node);
|
|
1015
|
+
}
|
|
1016
|
+
/** A static block as an expression to evaluate after the class: an arrow function called in place. */
|
|
1017
|
+
transformClassStaticBlockDeclaration(node) {
|
|
1018
|
+
if (!this.shouldTransformPrivateElementsOrClassStaticBlocks)
|
|
1019
|
+
return undefined;
|
|
1020
|
+
const context = this.context;
|
|
1021
|
+
const factory = this.factory;
|
|
1022
|
+
if (isClassThisAssignmentBlock(context, node)) {
|
|
1023
|
+
const result = this.visitNode(node.body.statements.nodes[0].expression);
|
|
1024
|
+
// `_classThis = _classThis` does nothing.
|
|
1025
|
+
if (result instanceof BinaryExpression && isAssignmentExpression(result, true) && result.left === result.right)
|
|
1026
|
+
return undefined;
|
|
1027
|
+
return result;
|
|
1028
|
+
}
|
|
1029
|
+
if (isClassNamedEvaluationHelperBlock(context, node))
|
|
1030
|
+
return this.visitNode(node.body.statements.nodes[0].expression);
|
|
1031
|
+
context.startVariableEnvironment();
|
|
1032
|
+
const saved = this.currentClassElement;
|
|
1033
|
+
this.currentClassElement = node;
|
|
1034
|
+
let statements = this.visitArray(node.body.statements.nodes);
|
|
1035
|
+
this.currentClassElement = saved;
|
|
1036
|
+
statements = context.mergeEnvironment(statements, context.endVariableEnvironment());
|
|
1037
|
+
const iife = factory.createImmediatelyInvokedArrowFunction(statements);
|
|
1038
|
+
const arrow = skipParentheses(iife.expression);
|
|
1039
|
+
context.setOriginal(arrow, node);
|
|
1040
|
+
context.addEmitFlags(arrow, 4194304 /* EmitFlags.NoLexicalArguments */);
|
|
1041
|
+
// Keep the statements' range for detached comments, as in `static { // do }`.
|
|
1042
|
+
if (arrow instanceof ArrowFunction && arrow.body instanceof Block) {
|
|
1043
|
+
arrow.body.statements.pos = node.body.statements.pos;
|
|
1044
|
+
arrow.body.statements.end = node.body.statements.end;
|
|
1045
|
+
}
|
|
1046
|
+
context.setOriginal(iife, node);
|
|
1047
|
+
context.assignSourceMapRange(iife, node);
|
|
1048
|
+
context.addEmitFlags(arrow, 16777216 /* EmitFlags.NoLexicalThis */);
|
|
1049
|
+
return iife;
|
|
1050
|
+
}
|
|
1051
|
+
visitBinaryExpression(node, discarded) {
|
|
1052
|
+
const factory = this.factory;
|
|
1053
|
+
const context = this.context;
|
|
1054
|
+
if (isDestructuringAssignment(node)) {
|
|
1055
|
+
// `({ x: obj.#x } = ...)`, `({ x: super.x } = ...)`
|
|
1056
|
+
const saved = this.pendingExpressions;
|
|
1057
|
+
this.pendingExpressions = [];
|
|
1058
|
+
const updated = factory.updateBinaryExpression(node, undefined, this.assignmentTargetMode.visitNode(node.left), undefined, node.operatorToken, this.visitNode(node.right));
|
|
1059
|
+
const pending = this.pendingExpressions;
|
|
1060
|
+
this.pendingExpressions = saved;
|
|
1061
|
+
if (pending.length === 0)
|
|
1062
|
+
return updated;
|
|
1063
|
+
pending.push(updated);
|
|
1064
|
+
return factory.inlineExpressions(pending);
|
|
1065
|
+
}
|
|
1066
|
+
let current = node;
|
|
1067
|
+
if (isAssignmentExpression(node, false)) {
|
|
1068
|
+
const named = this.transformNamedEvaluationIfNeeded(node, '');
|
|
1069
|
+
current = named;
|
|
1070
|
+
const left = skipOuterExpressions(named.left, 8 /* OuterExpressionKinds.PartiallyEmittedExpressions */ | 1 /* OuterExpressionKinds.Parentheses */);
|
|
1071
|
+
if (left instanceof PropertyAccessExpression && left.name instanceof PrivateIdentifier) {
|
|
1072
|
+
// `obj.#x = ...`
|
|
1073
|
+
const info = this.accessPrivateIdentifier(left.name);
|
|
1074
|
+
if (info !== undefined) {
|
|
1075
|
+
const result = this.createPrivateIdentifierAssignment(info, left.expression, named.right, named.operatorToken.kind);
|
|
1076
|
+
context.setOriginal(result, named);
|
|
1077
|
+
return this.withRange(result, named);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
else {
|
|
1081
|
+
const data = this.staticSuperData(named.left);
|
|
1082
|
+
if (data !== undefined) {
|
|
1083
|
+
if ((data.facts & 1 /* ClassFacts.ClassWasDecorated */) !== 0)
|
|
1084
|
+
return factory.updateBinaryExpression(named, undefined, this.visitInvalidSuperProperty(named.left), undefined, named.operatorToken, this.visitNode(named.right));
|
|
1085
|
+
if (data.classConstructor !== undefined && data.superClassReference !== undefined) {
|
|
1086
|
+
const assigned = this.transformSuperPropertyAssignment(named, data, discarded);
|
|
1087
|
+
if (assigned !== undefined)
|
|
1088
|
+
return assigned;
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
if (current.operatorToken.kind === 102 /* SyntaxKind.InKeyword */ && current.left instanceof PrivateIdentifier)
|
|
1094
|
+
return this.transformPrivateIdentifierInInExpression(current);
|
|
1095
|
+
return this.visitEachChild(current);
|
|
1096
|
+
}
|
|
1097
|
+
/** `super.x = 1` becomes `(Reflect.set(_baseTemp, "x", _a = 1, _classTemp), _a)`. */
|
|
1098
|
+
transformSuperPropertyAssignment(node, data, discarded) {
|
|
1099
|
+
const factory = this.factory;
|
|
1100
|
+
const context = this.context;
|
|
1101
|
+
const left = node.left;
|
|
1102
|
+
let setterName = undefined;
|
|
1103
|
+
if (left instanceof ElementAccessExpression)
|
|
1104
|
+
setterName = this.visitNode(left.argumentExpression);
|
|
1105
|
+
else if (left instanceof PropertyAccessExpression && left.name instanceof Identifier)
|
|
1106
|
+
setterName = factory.createStringLiteralFromNode(left.name);
|
|
1107
|
+
if (setterName === undefined)
|
|
1108
|
+
return undefined;
|
|
1109
|
+
const superClass = data.superClassReference;
|
|
1110
|
+
const classConstructor = data.classConstructor;
|
|
1111
|
+
let expression = this.visitNode(node.right);
|
|
1112
|
+
const operator = node.operatorToken.kind;
|
|
1113
|
+
if (isCompoundAssignment(operator)) {
|
|
1114
|
+
let getterName = setterName;
|
|
1115
|
+
if (!isSimpleInlineableExpression(setterName)) {
|
|
1116
|
+
const temp = context.addVariableDeclaration(factory.createTempVariable(0));
|
|
1117
|
+
getterName = temp;
|
|
1118
|
+
setterName = factory.createAssignment(temp, setterName);
|
|
1119
|
+
}
|
|
1120
|
+
const get = factory.createReflectGetCall(superClass, getterName, classConstructor);
|
|
1121
|
+
context.setOriginal(get, left);
|
|
1122
|
+
this.withRange(get, left);
|
|
1123
|
+
expression = this.withRange(factory.createBinaryExpression(get, nonAssignmentOperatorForCompoundAssignment(operator), expression), node);
|
|
1124
|
+
}
|
|
1125
|
+
let temp = undefined;
|
|
1126
|
+
if (!discarded) {
|
|
1127
|
+
temp = context.addVariableDeclaration(factory.createTempVariable(0));
|
|
1128
|
+
expression = this.withRange(factory.createAssignment(temp, expression), node);
|
|
1129
|
+
}
|
|
1130
|
+
expression = factory.createReflectSetCall(superClass, setterName, expression, classConstructor);
|
|
1131
|
+
context.setOriginal(expression, node);
|
|
1132
|
+
this.withRange(expression, node);
|
|
1133
|
+
if (temp !== undefined)
|
|
1134
|
+
expression = this.withRange(factory.createCommaExpression(expression, temp), node);
|
|
1135
|
+
return expression;
|
|
1136
|
+
}
|
|
1137
|
+
createPrivateIdentifierAssignment(info, receiverExpression, rightExpression, operator) {
|
|
1138
|
+
const factory = this.factory;
|
|
1139
|
+
let receiver = this.visitNode(receiverExpression);
|
|
1140
|
+
let right = this.visitNode(rightExpression);
|
|
1141
|
+
if (isCompoundAssignment(operator)) {
|
|
1142
|
+
const copiable = this.createCopiableReceiver(receiver);
|
|
1143
|
+
receiver = copiable.initialize !== undefined ? copiable.initialize : copiable.read;
|
|
1144
|
+
right = factory.createBinaryExpression(this.createPrivateIdentifierAccessHelper(info, copiable.read), nonAssignmentOperatorForCompoundAssignment(operator), right);
|
|
1145
|
+
}
|
|
1146
|
+
this.context.setCommentRange(receiver, -1, receiver.end);
|
|
1147
|
+
const state = info.brandCheckIdentifier;
|
|
1148
|
+
switch (info.kind) {
|
|
1149
|
+
case 2 /* PrivateKind.Accessor */:
|
|
1150
|
+
return factory.createClassPrivateFieldSetHelper(receiver, state, right, 'a', info.setterName);
|
|
1151
|
+
case 1 /* PrivateKind.Method */:
|
|
1152
|
+
return factory.createClassPrivateFieldSetHelper(receiver, state, right, 'm', undefined);
|
|
1153
|
+
case 0 /* PrivateKind.Field */:
|
|
1154
|
+
return factory.createClassPrivateFieldSetHelper(receiver, state, right, 'f', info.isStatic ? info.variableName : undefined);
|
|
1155
|
+
}
|
|
1156
|
+
throw new Error('Access helpers should not be created for untransformed private elements');
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Whether the body or initializer of `member` refers to the class `classNode` by name, which then
|
|
1160
|
+
* needs an alias once the member's code moves out of the class.
|
|
1161
|
+
*/
|
|
1162
|
+
memberContainsConstructorReference(member, classNode) {
|
|
1163
|
+
const finder = new ConstructorReferenceFinder(this.resolver, this.context.mostOriginal(classNode), getNameOfDeclaration(classNode));
|
|
1164
|
+
const body = member instanceof ClassStaticBlockDeclaration ? member.body : getBody(member);
|
|
1165
|
+
if (body !== undefined && finder.check(body))
|
|
1166
|
+
return true;
|
|
1167
|
+
if (member instanceof PropertyDeclaration && member.initializer !== undefined && finder.check(member.initializer))
|
|
1168
|
+
return true;
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
classContainsConstructorReference(node) {
|
|
1172
|
+
const members = membersOf(node);
|
|
1173
|
+
for (let i = 0; i < members.length; i++)
|
|
1174
|
+
if (this.memberContainsConstructorReference(members[i], node))
|
|
1175
|
+
return true;
|
|
1176
|
+
return false;
|
|
1177
|
+
}
|
|
1178
|
+
getClassFacts(node) {
|
|
1179
|
+
const context = this.context;
|
|
1180
|
+
let facts = 0 /* ClassFacts.None */;
|
|
1181
|
+
const original = context.mostOriginal(node);
|
|
1182
|
+
if (isClassLike(original) && classOrConstructorParameterIsDecorated(this.legacyDecorators, original))
|
|
1183
|
+
facts |= 1 /* ClassFacts.ClassWasDecorated */;
|
|
1184
|
+
const members = membersOf(node);
|
|
1185
|
+
if (this.shouldTransformPrivateElementsOrClassStaticBlocks &&
|
|
1186
|
+
(classHasClassThisAssignment(context, getClassMembers(node)) || classHasExplicitlyAssignedName(context, node)))
|
|
1187
|
+
facts |= 2 /* ClassFacts.NeedsClassConstructorReference */;
|
|
1188
|
+
let containsPublicInstanceFields = false;
|
|
1189
|
+
let containsInitializedPublicInstanceFields = false;
|
|
1190
|
+
let containsInstancePrivateElements = false;
|
|
1191
|
+
let containsInstanceAutoAccessors = false;
|
|
1192
|
+
for (let i = 0; i < members.length; i++) {
|
|
1193
|
+
const member = members[i];
|
|
1194
|
+
const name = getName(member);
|
|
1195
|
+
if (isStatic(member)) {
|
|
1196
|
+
if (name !== undefined &&
|
|
1197
|
+
(name.kind === 80 /* SyntaxKind.PrivateIdentifier */ || isAutoAccessorPropertyDeclaration(member)) &&
|
|
1198
|
+
this.shouldTransformPrivateElementsOrClassStaticBlocks)
|
|
1199
|
+
facts |= 2 /* ClassFacts.NeedsClassConstructorReference */;
|
|
1200
|
+
else if (isAutoAccessorPropertyDeclaration(member) &&
|
|
1201
|
+
this.shouldTransformAutoAccessors &&
|
|
1202
|
+
getName(node) === undefined &&
|
|
1203
|
+
context.getClassThis(node) === undefined)
|
|
1204
|
+
facts |= 2 /* ClassFacts.NeedsClassConstructorReference */;
|
|
1205
|
+
if (member instanceof PropertyDeclaration || member instanceof ClassStaticBlockDeclaration) {
|
|
1206
|
+
if (this.shouldTransformThisInStaticInitializers &&
|
|
1207
|
+
this.facts.has(member, 2048 /* SubtreeFacts.ContainsLexicalThis */)) {
|
|
1208
|
+
facts |= 8 /* ClassFacts.NeedsSubstitutionForThisInClassStaticField */;
|
|
1209
|
+
if ((facts & 1 /* ClassFacts.ClassWasDecorated */) === 0)
|
|
1210
|
+
facts |= 2 /* ClassFacts.NeedsClassConstructorReference */;
|
|
1211
|
+
}
|
|
1212
|
+
if (this.shouldTransformThisInStaticInitializers &&
|
|
1213
|
+
this.facts.has(member, 4096 /* SubtreeFacts.ContainsLexicalSuper */) &&
|
|
1214
|
+
(facts & 1 /* ClassFacts.ClassWasDecorated */) === 0)
|
|
1215
|
+
facts |= 2 /* ClassFacts.NeedsClassConstructorReference */ | 4 /* ClassFacts.NeedsClassSuperReference */;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
else if (!hasSyntacticModifier(context.mostOriginal(member), 64 /* ModifierFlags.Abstract */)) {
|
|
1219
|
+
if (isAutoAccessorPropertyDeclaration(member)) {
|
|
1220
|
+
containsInstanceAutoAccessors = true;
|
|
1221
|
+
if (isPrivateIdentifierClassElementDeclaration(member))
|
|
1222
|
+
containsInstancePrivateElements = true;
|
|
1223
|
+
}
|
|
1224
|
+
else if (isPrivateIdentifierClassElementDeclaration(member)) {
|
|
1225
|
+
containsInstancePrivateElements = true;
|
|
1226
|
+
if (this.memberContainsConstructorReference(member, node))
|
|
1227
|
+
facts |= 2 /* ClassFacts.NeedsClassConstructorReference */;
|
|
1228
|
+
}
|
|
1229
|
+
else if (member instanceof PropertyDeclaration) {
|
|
1230
|
+
containsPublicInstanceFields = true;
|
|
1231
|
+
if (member.initializer !== undefined)
|
|
1232
|
+
containsInitializedPublicInstanceFields = true;
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
const transformPrivate = this.shouldTransformPrivateElementsOrClassStaticBlocks;
|
|
1237
|
+
if ((this.shouldTransformInitializersUsingDefine && containsPublicInstanceFields) ||
|
|
1238
|
+
(this.shouldTransformInitializersUsingSet && containsInitializedPublicInstanceFields) ||
|
|
1239
|
+
(transformPrivate && containsInstancePrivateElements) ||
|
|
1240
|
+
(transformPrivate && containsInstanceAutoAccessors && this.shouldTransformAutoAccessors))
|
|
1241
|
+
facts |= 16 /* ClassFacts.WillHoistInitializersToConstructor */;
|
|
1242
|
+
return facts;
|
|
1243
|
+
}
|
|
1244
|
+
visitExpressionWithTypeArgumentsInHeritageClause(node) {
|
|
1245
|
+
if ((this.currentClassFacts() & 4 /* ClassFacts.NeedsClassSuperReference */) !== 0) {
|
|
1246
|
+
const factory = this.factory;
|
|
1247
|
+
const temp = this.context.addVariableDeclaration(factory.createTempVariable(8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */));
|
|
1248
|
+
this.getClassData().superClassReference = temp;
|
|
1249
|
+
return factory.updateExpressionWithTypeArguments(node, factory.createAssignment(temp, this.visitNode(node.expression)), undefined);
|
|
1250
|
+
}
|
|
1251
|
+
return this.heritageMode.visitEachChild(node);
|
|
1252
|
+
}
|
|
1253
|
+
/** Visits a class in a new class lexical environment. */
|
|
1254
|
+
visitClassLike(node) {
|
|
1255
|
+
const savedContainer = this.currentClassContainer;
|
|
1256
|
+
const savedPending = this.pendingExpressions;
|
|
1257
|
+
const savedEnvironment = this.lexicalEnvironment;
|
|
1258
|
+
this.currentClassContainer = node;
|
|
1259
|
+
this.pendingExpressions = [];
|
|
1260
|
+
this.lexicalEnvironment = new ClassEnvironment(savedEnvironment);
|
|
1261
|
+
const context = this.context;
|
|
1262
|
+
const original = context.mostOriginal(node);
|
|
1263
|
+
this.enclosingClassDeclarations.add(original);
|
|
1264
|
+
if (this.shouldTransformPrivateElementsOrClassStaticBlocks || this.hasTransformPrivateStaticElementsFlag(node)) {
|
|
1265
|
+
const name = getNameOfDeclaration(node);
|
|
1266
|
+
if (name instanceof Identifier)
|
|
1267
|
+
this.getPrivateEnvironment().className = name;
|
|
1268
|
+
else {
|
|
1269
|
+
const assignedName = context.getAssignedName(node);
|
|
1270
|
+
if (assignedName instanceof StringLiteral) {
|
|
1271
|
+
const textSource = context.getTextSource(assignedName);
|
|
1272
|
+
if (textSource instanceof Identifier)
|
|
1273
|
+
this.getPrivateEnvironment().className = textSource;
|
|
1274
|
+
else if (isIdentifierText(assignedName.text))
|
|
1275
|
+
this.getPrivateEnvironment().className = this.factory.createIdentifier(assignedName.text);
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
if (this.shouldTransformPrivateElementsOrClassStaticBlocks) {
|
|
1280
|
+
const methods = privateInstanceMethodsAndAccessors(node);
|
|
1281
|
+
if (methods.length > 0)
|
|
1282
|
+
this.getPrivateEnvironment().weakSetName = this.createHoistedVariableForClass('instances', getName(methods[0]), '');
|
|
1283
|
+
}
|
|
1284
|
+
const facts = this.getClassFacts(node);
|
|
1285
|
+
if (facts !== 0 /* ClassFacts.None */)
|
|
1286
|
+
this.getClassData().facts = facts;
|
|
1287
|
+
const result = node instanceof ClassDeclaration
|
|
1288
|
+
? this.visitClassDeclarationInEnvironment(node, facts)
|
|
1289
|
+
: this.visitClassExpressionInEnvironment(node, facts);
|
|
1290
|
+
this.enclosingClassDeclarations.delete(original);
|
|
1291
|
+
this.currentClassContainer = savedContainer;
|
|
1292
|
+
this.pendingExpressions = savedPending;
|
|
1293
|
+
this.lexicalEnvironment = savedEnvironment;
|
|
1294
|
+
return result;
|
|
1295
|
+
}
|
|
1296
|
+
visitClassDeclarationInEnvironment(node, facts) {
|
|
1297
|
+
const factory = this.factory;
|
|
1298
|
+
const context = this.context;
|
|
1299
|
+
// Private statics and static `this` or `super` need a reference to the class.
|
|
1300
|
+
let pendingClassReferenceAssignment = undefined;
|
|
1301
|
+
const classThis = classThisOf(context, node);
|
|
1302
|
+
if ((facts & 2 /* ClassFacts.NeedsClassConstructorReference */) !== 0) {
|
|
1303
|
+
// Reusing `_classThis` is only safe when static blocks are transformed too: the assignment
|
|
1304
|
+
// then runs before them, so it doesn't overwrite a replacement constructor from decorators.
|
|
1305
|
+
if (this.shouldTransformPrivateElementsOrClassStaticBlocks && classThis !== undefined) {
|
|
1306
|
+
this.getClassData().classConstructor = classThis;
|
|
1307
|
+
pendingClassReferenceAssignment = factory.createAssignment(classThis, factory.getLocalName(node, 0 /* NameOptions.None */));
|
|
1308
|
+
}
|
|
1309
|
+
else {
|
|
1310
|
+
const temp = context.addVariableDeclaration(factory.createTempVariable(8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */));
|
|
1311
|
+
this.getClassData().classConstructor = factory.cloneIdentifier(temp);
|
|
1312
|
+
pendingClassReferenceAssignment = factory.createAssignment(temp, factory.getLocalName(node, 0 /* NameOptions.None */));
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
if (classThis !== undefined)
|
|
1316
|
+
this.getClassData().classThis = classThis;
|
|
1317
|
+
// Aliases are registered before visiting members, which substitute eagerly.
|
|
1318
|
+
const alias = this.getClassData().classConstructor;
|
|
1319
|
+
if (alias !== undefined && this.classContainsConstructorReference(node))
|
|
1320
|
+
this.classAliases.set(context.mostOriginal(node), alias);
|
|
1321
|
+
let modifiers = this.modifierMode.visitModifiers(node.modifiers);
|
|
1322
|
+
const heritageClauses = this.heritageMode.visitNodes(node.heritageClauses);
|
|
1323
|
+
const transformed = this.transformClassMembers(node);
|
|
1324
|
+
const statements = [];
|
|
1325
|
+
if (pendingClassReferenceAssignment !== undefined)
|
|
1326
|
+
this.pendingExpressions.unshift(pendingClassReferenceAssignment);
|
|
1327
|
+
// Expressions from elided or moved computed property names.
|
|
1328
|
+
if (this.pendingExpressions.length > 0)
|
|
1329
|
+
statements.push(factory.createExpressionStatement(factory.inlineExpressions(this.pendingExpressions)));
|
|
1330
|
+
let name = node.name;
|
|
1331
|
+
if (this.shouldTransformInitializersUsingSet || this.shouldTransformPrivateElementsOrClassStaticBlocks) {
|
|
1332
|
+
// Static initializers run after the class, which is safe because the declaration is lexical.
|
|
1333
|
+
const statics = staticPropertiesAndClassStaticBlocks(node);
|
|
1334
|
+
if (statics.length > 0) {
|
|
1335
|
+
if (name === undefined)
|
|
1336
|
+
name = factory.createGeneratedNameForNode(node, 0, '', '');
|
|
1337
|
+
this.addPropertyOrClassStaticBlockStatements(statements, statics, factory.getLocalName(node, 0 /* NameOptions.None */));
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
if (statements.length > 0 &&
|
|
1341
|
+
hasSyntacticModifier(node, 32 /* ModifierFlags.Export */) &&
|
|
1342
|
+
hasSyntacticModifier(node, 2048 /* ModifierFlags.Default */)) {
|
|
1343
|
+
modifiers = this.extractModifiers(modifiers, ~(32 /* ModifierFlags.Export */ | 2048 /* ModifierFlags.Default */));
|
|
1344
|
+
statements.push(factory.created(new ExportAssignment(undefined, false, undefined, factory.getLocalName(node, 0 /* NameOptions.None */))));
|
|
1345
|
+
}
|
|
1346
|
+
const updated = factory.updateClassDeclaration(node, modifiers, name, undefined, heritageClauses, transformed.members);
|
|
1347
|
+
const result = [];
|
|
1348
|
+
if (transformed.prologue !== undefined)
|
|
1349
|
+
result.push(factory.createExpressionStatement(transformed.prologue));
|
|
1350
|
+
result.push(updated);
|
|
1351
|
+
for (let i = 0; i < statements.length; i++)
|
|
1352
|
+
result.push(statements[i]);
|
|
1353
|
+
return factory.createSyntaxList(result);
|
|
1354
|
+
}
|
|
1355
|
+
createClassTemp() {
|
|
1356
|
+
const temp = this.factory.createTempVariable(8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */);
|
|
1357
|
+
return temp;
|
|
1358
|
+
}
|
|
1359
|
+
visitClassExpressionInEnvironment(node, facts) {
|
|
1360
|
+
const factory = this.factory;
|
|
1361
|
+
const context = this.context;
|
|
1362
|
+
// A class expression from a decorated class declaration puts its statics in statements after
|
|
1363
|
+
// the variable statement, as the declaration would.
|
|
1364
|
+
const isDecoratedClassDeclaration = (facts & 1 /* ClassFacts.ClassWasDecorated */) !== 0;
|
|
1365
|
+
const classThis = classThisOf(context, node);
|
|
1366
|
+
if (classThis !== undefined)
|
|
1367
|
+
this.getClassData().classThis = classThis;
|
|
1368
|
+
let temp = undefined;
|
|
1369
|
+
if ((facts & 2 /* ClassFacts.NeedsClassConstructorReference */) !== 0) {
|
|
1370
|
+
if ((this.shouldTransformPrivateElementsOrClassStaticBlocks || this.hasTransformPrivateStaticElementsFlag(node)) &&
|
|
1371
|
+
classThis !== undefined) {
|
|
1372
|
+
this.getClassData().classConstructor = classThis;
|
|
1373
|
+
temp = classThis;
|
|
1374
|
+
}
|
|
1375
|
+
else {
|
|
1376
|
+
temp = this.addHoisted(this.createClassTemp(), this.classExpressionNeedsBlockScopedTemp());
|
|
1377
|
+
this.getClassData().classConstructor = factory.cloneIdentifier(temp);
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
const statics = staticPropertiesAndClassStaticBlocks(node);
|
|
1381
|
+
// Aliases must be known before visiting members, so predict whether a temporary will wrap the class.
|
|
1382
|
+
let isClassWithConstructorReference = false;
|
|
1383
|
+
let hasTransformableStatics = false;
|
|
1384
|
+
let deferTempDeclaration = false;
|
|
1385
|
+
if (!isDecoratedClassDeclaration) {
|
|
1386
|
+
isClassWithConstructorReference = this.classContainsConstructorReference(node);
|
|
1387
|
+
hasTransformableStatics = this.hasTransformableStatics(node, statics);
|
|
1388
|
+
let willHavePrivatePendingExpressions = false;
|
|
1389
|
+
if (this.shouldTransformPrivateElementsOrClassStaticBlocks) {
|
|
1390
|
+
const members = node.members.nodes;
|
|
1391
|
+
for (let i = 0; i < members.length; i++) {
|
|
1392
|
+
const member = members[i];
|
|
1393
|
+
if (isPrivateIdentifierClassElementDeclaration(member) &&
|
|
1394
|
+
!hasStaticModifier(member) &&
|
|
1395
|
+
this.shouldTransformClassElementToWeakMap(member)) {
|
|
1396
|
+
willHavePrivatePendingExpressions = true;
|
|
1397
|
+
break;
|
|
1398
|
+
}
|
|
1399
|
+
}
|
|
1400
|
+
}
|
|
1401
|
+
const willNeedTempWrapper = hasTransformableStatics || willHavePrivatePendingExpressions;
|
|
1402
|
+
if (isClassWithConstructorReference &&
|
|
1403
|
+
willNeedTempWrapper &&
|
|
1404
|
+
this.getClassData().classConstructor === undefined) {
|
|
1405
|
+
// Declared after the members are visited, to keep tsc's declaration order.
|
|
1406
|
+
temp = this.createClassTemp();
|
|
1407
|
+
deferTempDeclaration = true;
|
|
1408
|
+
this.getClassData().classConstructor = factory.cloneIdentifier(temp);
|
|
1409
|
+
}
|
|
1410
|
+
const alias = this.getClassData().classConstructor;
|
|
1411
|
+
if (isClassWithConstructorReference && willNeedTempWrapper && alias !== undefined)
|
|
1412
|
+
this.classAliases.set(context.mostOriginal(node), alias);
|
|
1413
|
+
}
|
|
1414
|
+
const modifiers = this.modifierMode.visitModifiers(node.modifiers);
|
|
1415
|
+
const heritageClauses = this.heritageMode.visitNodes(node.heritageClauses);
|
|
1416
|
+
const transformed = this.transformClassMembers(node);
|
|
1417
|
+
if (deferTempDeclaration)
|
|
1418
|
+
this.addHoisted(temp, this.classExpressionNeedsBlockScopedTemp());
|
|
1419
|
+
const classExpression = factory.updateClassExpression(node, modifiers, node.name, undefined, heritageClauses, transformed.members);
|
|
1420
|
+
const expressions = [];
|
|
1421
|
+
if (transformed.prologue !== undefined)
|
|
1422
|
+
expressions.push(transformed.prologue);
|
|
1423
|
+
if (!isDecoratedClassDeclaration) {
|
|
1424
|
+
if (hasTransformableStatics || this.pendingExpressions.length > 0) {
|
|
1425
|
+
if (temp === undefined) {
|
|
1426
|
+
temp = this.addHoisted(this.createClassTemp(), this.classExpressionNeedsBlockScopedTemp());
|
|
1427
|
+
const alias = factory.cloneIdentifier(temp);
|
|
1428
|
+
this.getClassData().classConstructor = alias;
|
|
1429
|
+
if (isClassWithConstructorReference)
|
|
1430
|
+
this.classAliases.set(context.mostOriginal(node), alias);
|
|
1431
|
+
}
|
|
1432
|
+
expressions.push(factory.createAssignment(temp, classExpression));
|
|
1433
|
+
// Expressions left from elided or moved computed property names.
|
|
1434
|
+
for (let i = 0; i < this.pendingExpressions.length; i++)
|
|
1435
|
+
expressions.push(this.pendingExpressions[i]);
|
|
1436
|
+
const initializers = this.generateInitializedPropertyExpressionsOrClassStaticBlock(statics, temp);
|
|
1437
|
+
for (let i = 0; i < initializers.length; i++)
|
|
1438
|
+
expressions.push(initializers[i]);
|
|
1439
|
+
expressions.push(factory.cloneIdentifier(temp));
|
|
1440
|
+
}
|
|
1441
|
+
else
|
|
1442
|
+
expressions.push(classExpression);
|
|
1443
|
+
}
|
|
1444
|
+
else {
|
|
1445
|
+
for (let i = 0; i < this.pendingExpressions.length; i++)
|
|
1446
|
+
this.pendingStatements.push(factory.createExpressionStatement(this.pendingExpressions[i]));
|
|
1447
|
+
if (statics.length > 0) {
|
|
1448
|
+
const receiver = classThis !== undefined ? classThis : factory.getLocalName(node, 0 /* NameOptions.None */);
|
|
1449
|
+
this.addPropertyOrClassStaticBlockStatements(this.pendingStatements, statics, receiver);
|
|
1450
|
+
}
|
|
1451
|
+
if (temp !== undefined)
|
|
1452
|
+
expressions.push(factory.createAssignment(temp, classExpression));
|
|
1453
|
+
else if (this.shouldTransformPrivateElementsOrClassStaticBlocks && classThis !== undefined)
|
|
1454
|
+
expressions.push(factory.createAssignment(classThis, classExpression));
|
|
1455
|
+
else
|
|
1456
|
+
expressions.push(classExpression);
|
|
1457
|
+
}
|
|
1458
|
+
if (expressions.length > 1) {
|
|
1459
|
+
context.addEmitFlags(classExpression, 8192 /* EmitFlags.Indented */);
|
|
1460
|
+
for (let i = 0; i < expressions.length; i++)
|
|
1461
|
+
context.addEmitFlags(expressions[i], 524288 /* EmitFlags.StartOnNewLine */);
|
|
1462
|
+
}
|
|
1463
|
+
return factory.inlineExpressions(expressions);
|
|
1464
|
+
}
|
|
1465
|
+
/** `this` in a static initializer, or a computed name, of a class whose code moves out of its body. */
|
|
1466
|
+
visitThisExpression(node) {
|
|
1467
|
+
const environment = this.lexicalEnvironment;
|
|
1468
|
+
if (environment === undefined || environment.data === undefined || !this.shouldTransformThisInStaticInitializers)
|
|
1469
|
+
return node;
|
|
1470
|
+
const data = environment.data;
|
|
1471
|
+
// Computed names of ES-decorated classes are already in an arrow function seeing the outer `this`.
|
|
1472
|
+
if (this.insideComputedPropertyName &&
|
|
1473
|
+
((data.facts & 1 /* ClassFacts.ClassWasDecorated */) === 0 || this.legacyDecorators)) {
|
|
1474
|
+
const classThis = this.tryGetClassThisNoContainer();
|
|
1475
|
+
if (classThis !== undefined)
|
|
1476
|
+
return classThis;
|
|
1477
|
+
}
|
|
1478
|
+
const element = this.currentClassElement;
|
|
1479
|
+
if (element !== undefined && isStaticPropertyDeclarationOrClassStaticBlock(element)) {
|
|
1480
|
+
const classThis = this.tryGetClassThisNoContainer();
|
|
1481
|
+
if (classThis !== undefined)
|
|
1482
|
+
return classThis;
|
|
1483
|
+
// A legacy decorator may replace the class, so `this` can't name it.
|
|
1484
|
+
if ((data.facts & 1 /* ClassFacts.ClassWasDecorated */) !== 0 && this.legacyDecorators)
|
|
1485
|
+
return this.factory.createParenthesizedExpression(this.factory.createVoidZero());
|
|
1486
|
+
}
|
|
1487
|
+
return node;
|
|
1488
|
+
}
|
|
1489
|
+
transformClassMembers(node) {
|
|
1490
|
+
const factory = this.factory;
|
|
1491
|
+
const context = this.context;
|
|
1492
|
+
const memberList = getMembers(node);
|
|
1493
|
+
const memberNodes = memberList.nodes;
|
|
1494
|
+
const privateStaticsInClass = this.hasTransformPrivateStaticElementsFlag(node);
|
|
1495
|
+
// Declare private names.
|
|
1496
|
+
if (this.shouldTransformPrivateElementsOrClassStaticBlocks || this.shouldTransformPrivateStaticElementsInFile) {
|
|
1497
|
+
for (let i = 0; i < memberNodes.length; i++) {
|
|
1498
|
+
const member = memberNodes[i];
|
|
1499
|
+
if (!isPrivateIdentifierClassElementDeclaration(member))
|
|
1500
|
+
continue;
|
|
1501
|
+
if (this.shouldTransformClassElementToWeakMap(member))
|
|
1502
|
+
this.addPrivateIdentifierToEnvironment(member);
|
|
1503
|
+
else
|
|
1504
|
+
this.setPrivateIdentifier(this.getPrivateEnvironment(), getName(member), new PrivateIdentifierInfo(3 /* PrivateKind.Untransformed */, undefined, false, false));
|
|
1505
|
+
}
|
|
1506
|
+
if (this.shouldTransformPrivateElementsOrClassStaticBlocks && privateInstanceMethodsAndAccessors(node).length > 0)
|
|
1507
|
+
this.createBrandCheckWeakSetForPrivateMethods(this.getPrivateEnvironment());
|
|
1508
|
+
if (this.shouldTransformAutoAccessorsInCurrentClass()) {
|
|
1509
|
+
for (let i = 0; i < memberNodes.length; i++) {
|
|
1510
|
+
const member = memberNodes[i];
|
|
1511
|
+
if (!isAutoAccessorPropertyDeclaration(member))
|
|
1512
|
+
continue;
|
|
1513
|
+
const storageName = factory.createGeneratedPrivateNameForNode(getName(member), '', accessorStorageSuffix);
|
|
1514
|
+
if (this.shouldTransformPrivateElementsOrClassStaticBlocks ||
|
|
1515
|
+
(privateStaticsInClass && hasStaticModifier(member)))
|
|
1516
|
+
this.addPrivateIdentifierPropertyDeclarationToEnvironment(member, storageName);
|
|
1517
|
+
else {
|
|
1518
|
+
// Unless the first loop declared it, as for a private auto-accessor expanded by ES decorators.
|
|
1519
|
+
const environment = this.getPrivateEnvironment();
|
|
1520
|
+
if (this.getPrivateIdentifier(environment, storageName) === undefined)
|
|
1521
|
+
this.setPrivateIdentifier(environment, storageName, new PrivateIdentifierInfo(3 /* PrivateKind.Untransformed */, undefined, false, false));
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
let members = this.classElementMode.visitNodes(memberList);
|
|
1527
|
+
let syntheticConstructor = undefined;
|
|
1528
|
+
let hasConstructor = false;
|
|
1529
|
+
for (let i = 0; i < members.nodes.length; i++)
|
|
1530
|
+
if (members.nodes[i].kind === 177 /* SyntaxKind.Constructor */)
|
|
1531
|
+
hasConstructor = true;
|
|
1532
|
+
if (!hasConstructor)
|
|
1533
|
+
syntheticConstructor = this.transformConstructor(undefined, node);
|
|
1534
|
+
// Without static blocks transformed, computed name expressions are evaluated in a static block
|
|
1535
|
+
// at the top of the class, before other static initializers.
|
|
1536
|
+
let syntheticStaticBlock = undefined;
|
|
1537
|
+
let prologue = undefined;
|
|
1538
|
+
if (!this.shouldTransformPrivateElementsOrClassStaticBlocks && this.pendingExpressions.length > 0) {
|
|
1539
|
+
let statement = factory.createExpressionStatement(factory.inlineExpressions(this.pendingExpressions));
|
|
1540
|
+
if (this.facts.has(statement, 6144 /* SubtreeFacts.ContainsLexicalThisOrSuper */)) {
|
|
1541
|
+
// `this` and `super` in computed names refer to the outer scope: evaluate them in an arrow function.
|
|
1542
|
+
const temp = context.addVariableDeclaration(factory.createTempVariable(0));
|
|
1543
|
+
const arrow = factory.createArrowFunction([], factory.createBlock([statement], false));
|
|
1544
|
+
prologue = factory.createAssignment(temp, arrow);
|
|
1545
|
+
statement = factory.createExpressionStatement(factory.createCallExpression(temp, []));
|
|
1546
|
+
}
|
|
1547
|
+
syntheticStaticBlock = factory.created(new ClassStaticBlockDeclaration(undefined, factory.createBlock([statement], false)));
|
|
1548
|
+
this.pendingExpressions = [];
|
|
1549
|
+
}
|
|
1550
|
+
if (syntheticConstructor !== undefined || syntheticStaticBlock !== undefined) {
|
|
1551
|
+
// The classThis and named evaluation blocks stay first.
|
|
1552
|
+
const nodes = members.nodes;
|
|
1553
|
+
let classThisIndex = -1;
|
|
1554
|
+
let namedEvaluationIndex = -1;
|
|
1555
|
+
for (let i = 0; i < nodes.length; i++)
|
|
1556
|
+
if (classThisIndex < 0 && isClassThisAssignmentBlock(context, nodes[i]))
|
|
1557
|
+
classThisIndex = i;
|
|
1558
|
+
for (let i = 0; i < nodes.length; i++)
|
|
1559
|
+
if (namedEvaluationIndex < 0 && isClassNamedEvaluationHelperBlock(context, nodes[i]))
|
|
1560
|
+
namedEvaluationIndex = i;
|
|
1561
|
+
const updated = [];
|
|
1562
|
+
if (classThisIndex >= 0)
|
|
1563
|
+
updated.push(nodes[classThisIndex]);
|
|
1564
|
+
if (namedEvaluationIndex >= 0)
|
|
1565
|
+
updated.push(nodes[namedEvaluationIndex]);
|
|
1566
|
+
if (syntheticConstructor !== undefined)
|
|
1567
|
+
updated.push(syntheticConstructor);
|
|
1568
|
+
if (syntheticStaticBlock !== undefined)
|
|
1569
|
+
updated.push(syntheticStaticBlock);
|
|
1570
|
+
for (let i = 0; i < nodes.length; i++)
|
|
1571
|
+
if (i !== classThisIndex && i !== namedEvaluationIndex)
|
|
1572
|
+
updated.push(nodes[i]);
|
|
1573
|
+
members = new NodeList(memberList.pos, memberList.end, updated);
|
|
1574
|
+
}
|
|
1575
|
+
return new ClassMembers(members, prologue);
|
|
1576
|
+
}
|
|
1577
|
+
createBrandCheckWeakSetForPrivateMethods(environment) {
|
|
1578
|
+
const factory = this.factory;
|
|
1579
|
+
this.pendingExpressions.push(factory.createAssignment(environment.weakSetName, factory.created(new NewExpression(factory.createIdentifier('WeakSet'), undefined, factory.createNodeList([])))));
|
|
1580
|
+
return true;
|
|
1581
|
+
}
|
|
1582
|
+
transformConstructor(constructor, container) {
|
|
1583
|
+
// Parameters and body are visited in the scopes of the new body, so hoisted variables come first.
|
|
1584
|
+
if ((this.currentClassFacts() & 16 /* ClassFacts.WillHoistInitializersToConstructor */) === 0)
|
|
1585
|
+
return constructor !== undefined ? this.visitEachChild(constructor) : undefined;
|
|
1586
|
+
const extendsElement = getClassExtendsHeritageElement(container);
|
|
1587
|
+
const isDerivedClass = extendsElement !== undefined &&
|
|
1588
|
+
skipOuterExpressions(extendsElement.expression, 63 /* OuterExpressionKinds.All */).kind !== 105 /* SyntaxKind.NullKeyword */;
|
|
1589
|
+
const parameters = constructor !== undefined ? this.visitNodes(constructor.parameters) : undefined;
|
|
1590
|
+
const body = this.transformConstructorBody(container, constructor, isDerivedClass);
|
|
1591
|
+
if (body === undefined)
|
|
1592
|
+
return constructor !== undefined ? this.visitEachChild(constructor) : undefined;
|
|
1593
|
+
const factory = this.factory;
|
|
1594
|
+
if (constructor !== undefined)
|
|
1595
|
+
return factory.updateConstructorDeclaration(constructor, undefined, undefined, parameters, undefined, undefined, body);
|
|
1596
|
+
const result = factory.created(new ConstructorDeclaration(undefined, undefined, factory.createNodeList([]), undefined, undefined, body));
|
|
1597
|
+
return this.withRange(result, container);
|
|
1598
|
+
}
|
|
1599
|
+
transformConstructorBodyWorker(statementsOut, statementsIn, start, superPath, depth, initializerStatements, constructor) {
|
|
1600
|
+
const superIndex = superPath[depth] | 0;
|
|
1601
|
+
const superStatement = statementsIn[superIndex];
|
|
1602
|
+
appendAll(statementsOut, this.visitArray(statementsIn.slice(start, superIndex)));
|
|
1603
|
+
let offset = superIndex + 1;
|
|
1604
|
+
if (superStatement instanceof TryStatement) {
|
|
1605
|
+
const tryBlock = superStatement.tryBlock;
|
|
1606
|
+
const inner = this.transformConstructorBodyWorker([], tryBlock.statements.nodes, 0, superPath, depth + 1, initializerStatements, constructor);
|
|
1607
|
+
const list = new NodeList(tryBlock.statements.pos, tryBlock.statements.end, inner);
|
|
1608
|
+
const catchClause = this.visitNode(superStatement.catchClause);
|
|
1609
|
+
const finallyBlock = this.visitNode(superStatement.finallyBlock);
|
|
1610
|
+
statementsOut.push(this.factory.updateTryStatement(superStatement, this.factory.updateBlock(tryBlock, list, tryBlock.multiLine), catchClause instanceof CatchClause ? catchClause : undefined, finallyBlock instanceof Block ? finallyBlock : undefined));
|
|
1611
|
+
}
|
|
1612
|
+
else {
|
|
1613
|
+
appendAll(statementsOut, this.visitArray([superStatement]));
|
|
1614
|
+
// Parameter property assignments directly follow `super()`; initializers go after them.
|
|
1615
|
+
offset = this.skipParameterPropertyAssignments(statementsIn, offset, constructor);
|
|
1616
|
+
appendAll(statementsOut, initializerStatements);
|
|
1617
|
+
}
|
|
1618
|
+
appendAll(statementsOut, this.visitArray(statementsIn.slice(offset)));
|
|
1619
|
+
return statementsOut;
|
|
1620
|
+
}
|
|
1621
|
+
skipParameterPropertyAssignments(statements, start, constructor) {
|
|
1622
|
+
let offset = start;
|
|
1623
|
+
while (offset < statements.length &&
|
|
1624
|
+
isParameterPropertyDeclaration(this.context.mostOriginal(statements[offset]), constructor))
|
|
1625
|
+
offset++;
|
|
1626
|
+
return offset;
|
|
1627
|
+
}
|
|
1628
|
+
transformConstructorBody(container, constructor, isDerivedClass) {
|
|
1629
|
+
const factory = this.factory;
|
|
1630
|
+
const context = this.context;
|
|
1631
|
+
const instanceProperties = propertiesOf(container, false);
|
|
1632
|
+
let properties = instanceProperties;
|
|
1633
|
+
if (!this.useDefineForClassFields)
|
|
1634
|
+
properties = withInitializerOrPrivateName(properties);
|
|
1635
|
+
const privateMethodsAndAccessors = privateInstanceMethodsAndAccessors(container);
|
|
1636
|
+
const needsConstructorBody = properties.length > 0 || privateMethodsAndAccessors.length > 0;
|
|
1637
|
+
if (constructor === undefined && !needsConstructorBody)
|
|
1638
|
+
return this.visitFunctionBody(undefined);
|
|
1639
|
+
context.startVariableEnvironment();
|
|
1640
|
+
const needsSyntheticConstructor = constructor === undefined && isDerivedClass;
|
|
1641
|
+
let statements = [];
|
|
1642
|
+
const initializerStatements = [];
|
|
1643
|
+
const receiver = factory.createThisExpression();
|
|
1644
|
+
// Private methods can be called in initializers, so their brand comes first.
|
|
1645
|
+
this.addInstanceMethodStatements(initializerStatements, privateMethodsAndAccessors, receiver);
|
|
1646
|
+
if (constructor !== undefined) {
|
|
1647
|
+
const parameterProperties = [];
|
|
1648
|
+
const others = [];
|
|
1649
|
+
for (let i = 0; i < instanceProperties.length; i++)
|
|
1650
|
+
if (isParameterPropertyDeclaration(context.mostOriginal(instanceProperties[i]), constructor))
|
|
1651
|
+
parameterProperties.push(instanceProperties[i]);
|
|
1652
|
+
for (let i = 0; i < properties.length; i++)
|
|
1653
|
+
if (!isParameterPropertyDeclaration(context.mostOriginal(properties[i]), constructor))
|
|
1654
|
+
others.push(properties[i]);
|
|
1655
|
+
this.addPropertyOrClassStaticBlockStatements(initializerStatements, parameterProperties, receiver);
|
|
1656
|
+
this.addPropertyOrClassStaticBlockStatements(initializerStatements, others, receiver);
|
|
1657
|
+
}
|
|
1658
|
+
else
|
|
1659
|
+
this.addPropertyOrClassStaticBlockStatements(initializerStatements, properties, receiver);
|
|
1660
|
+
const constructorBody = constructor !== undefined && constructor.body instanceof Block ? constructor.body : undefined;
|
|
1661
|
+
if (constructorBody !== undefined) {
|
|
1662
|
+
const nodes = constructorBody.statements.nodes;
|
|
1663
|
+
let offset = 0;
|
|
1664
|
+
while (offset < nodes.length && isPrologueDirective(nodes[offset]))
|
|
1665
|
+
statements.push(nodes[offset++]);
|
|
1666
|
+
const superPath = findSuperStatementIndexPath(nodes.slice(offset), 0);
|
|
1667
|
+
if (superPath.length > 0) {
|
|
1668
|
+
superPath[0] = (superPath[0] | 0) + offset;
|
|
1669
|
+
statements = this.transformConstructorBodyWorker(statements, nodes, offset, superPath, 0, initializerStatements, constructor);
|
|
1670
|
+
}
|
|
1671
|
+
else {
|
|
1672
|
+
offset = this.skipParameterPropertyAssignments(nodes, offset, constructor);
|
|
1673
|
+
appendAll(statements, initializerStatements);
|
|
1674
|
+
appendAll(statements, this.visitArray(nodes.slice(offset)));
|
|
1675
|
+
}
|
|
1676
|
+
}
|
|
1677
|
+
else {
|
|
1678
|
+
if (needsSyntheticConstructor)
|
|
1679
|
+
// `super(...arguments);`
|
|
1680
|
+
statements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createKeywordExpression(107 /* SyntaxKind.SuperKeyword */), [
|
|
1681
|
+
factory.created(new SpreadElement(factory.createIdentifier('arguments'))),
|
|
1682
|
+
])));
|
|
1683
|
+
appendAll(statements, initializerStatements);
|
|
1684
|
+
}
|
|
1685
|
+
statements = context.mergeEnvironment(statements, context.endVariableEnvironment());
|
|
1686
|
+
if (statements.length === 0 && constructor === undefined)
|
|
1687
|
+
return undefined;
|
|
1688
|
+
const multiLine = constructorBody !== undefined && constructorBody.statements.nodes.length >= statements.length
|
|
1689
|
+
? constructorBody.multiLine
|
|
1690
|
+
: statements.length > 0;
|
|
1691
|
+
const members = getMembers(container);
|
|
1692
|
+
const list = constructorBody !== undefined
|
|
1693
|
+
? new NodeList(constructorBody.statements.pos, constructorBody.statements.end, statements)
|
|
1694
|
+
: new NodeList(members.pos, members.end, statements);
|
|
1695
|
+
const block = factory.created(new Block(list, multiLine));
|
|
1696
|
+
if (constructorBody !== undefined)
|
|
1697
|
+
this.withRange(block, constructorBody);
|
|
1698
|
+
return block;
|
|
1699
|
+
}
|
|
1700
|
+
addPropertyOrClassStaticBlockStatements(statements, properties, receiver) {
|
|
1701
|
+
for (let i = 0; i < properties.length; i++) {
|
|
1702
|
+
const property = properties[i];
|
|
1703
|
+
if (isStatic(property) && !this.shouldTransformPrivateElementsOrClassStaticBlocks)
|
|
1704
|
+
continue;
|
|
1705
|
+
const statement = this.transformPropertyOrClassStaticBlock(property, receiver);
|
|
1706
|
+
if (statement !== undefined)
|
|
1707
|
+
statements.push(statement);
|
|
1708
|
+
}
|
|
1709
|
+
return true;
|
|
1710
|
+
}
|
|
1711
|
+
transformStaticBlockInElement(property) {
|
|
1712
|
+
const saved = this.currentClassElement;
|
|
1713
|
+
this.currentClassElement = property;
|
|
1714
|
+
const expression = this.transformClassStaticBlockDeclaration(property);
|
|
1715
|
+
this.currentClassElement = saved;
|
|
1716
|
+
return expression;
|
|
1717
|
+
}
|
|
1718
|
+
transformPropertyOrClassStaticBlock(property, receiver) {
|
|
1719
|
+
const context = this.context;
|
|
1720
|
+
const expression = property instanceof ClassStaticBlockDeclaration
|
|
1721
|
+
? this.transformStaticBlockInElement(property)
|
|
1722
|
+
: this.transformProperty(property, receiver);
|
|
1723
|
+
if (expression === undefined)
|
|
1724
|
+
return undefined;
|
|
1725
|
+
const statement = this.factory.createExpressionStatement(expression);
|
|
1726
|
+
context.setOriginal(statement, property);
|
|
1727
|
+
context.addEmitFlags(statement, context.getEmitFlags(property) & 384 /* EmitFlags.NoComments */);
|
|
1728
|
+
context.setCommentRange(statement, property.pos, property.end);
|
|
1729
|
+
const original = context.mostOriginal(property);
|
|
1730
|
+
if (original instanceof ParameterDeclaration) {
|
|
1731
|
+
context.setSourceMapRange(statement, original.pos, original.end);
|
|
1732
|
+
context.addEmitFlags(statement, 384 /* EmitFlags.NoComments */);
|
|
1733
|
+
}
|
|
1734
|
+
else
|
|
1735
|
+
context.setSourceMapRange(statement, posPastModifiers(property), property.end);
|
|
1736
|
+
// The statement got a copy of the synthesized comments; don't print them twice.
|
|
1737
|
+
context.setSyntheticLeadingComments(expression, undefined);
|
|
1738
|
+
context.setSyntheticTrailingComments(expression, undefined);
|
|
1739
|
+
// Comments of an auto-accessor go to its getter.
|
|
1740
|
+
if (hasSyntacticModifier(original, 512 /* ModifierFlags.Accessor */))
|
|
1741
|
+
context.addEmitFlags(statement, 384 /* EmitFlags.NoComments */);
|
|
1742
|
+
return statement;
|
|
1743
|
+
}
|
|
1744
|
+
generateInitializedPropertyExpressionsOrClassStaticBlock(properties, receiver) {
|
|
1745
|
+
const expressions = [];
|
|
1746
|
+
for (let i = 0; i < properties.length; i++) {
|
|
1747
|
+
const property = properties[i];
|
|
1748
|
+
const expression = property instanceof ClassStaticBlockDeclaration
|
|
1749
|
+
? this.transformStaticBlockInElement(property)
|
|
1750
|
+
: this.transformProperty(property, receiver);
|
|
1751
|
+
if (expression === undefined)
|
|
1752
|
+
continue;
|
|
1753
|
+
this.context.setOriginalEx(expression, property, true);
|
|
1754
|
+
this.context.assignCommentAndSourceMapRanges(expression, property);
|
|
1755
|
+
expressions.push(expression);
|
|
1756
|
+
}
|
|
1757
|
+
return expressions;
|
|
1758
|
+
}
|
|
1759
|
+
transformProperty(property, receiver) {
|
|
1760
|
+
const saved = this.currentClassElement;
|
|
1761
|
+
const transformed = this.transformPropertyWorker(property, receiver);
|
|
1762
|
+
if (transformed !== undefined && hasStaticModifier(property)) {
|
|
1763
|
+
const context = this.context;
|
|
1764
|
+
context.addEmitFlags(transformed, 16777216 /* EmitFlags.NoLexicalThis */);
|
|
1765
|
+
if (this.currentClassFacts() !== 0 /* ClassFacts.None */) {
|
|
1766
|
+
context.setOriginal(transformed, property);
|
|
1767
|
+
context.setSourceMapRange(transformed, context.sourceMapPos(property.name), context.sourceMapEnd(property.name));
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
this.currentClassElement = saved;
|
|
1771
|
+
return transformed;
|
|
1772
|
+
}
|
|
1773
|
+
transformPropertyWorker(node, receiver) {
|
|
1774
|
+
const factory = this.factory;
|
|
1775
|
+
const context = this.context;
|
|
1776
|
+
const emitAssignment = !this.useDefineForClassFields;
|
|
1777
|
+
const property = this.transformNamedEvaluationIfNeeded(node, '');
|
|
1778
|
+
// The generated name reuses the value cached by the moved computed name expression.
|
|
1779
|
+
let propertyName = property.name;
|
|
1780
|
+
if (hasSyntacticModifier(property, 512 /* ModifierFlags.Accessor */))
|
|
1781
|
+
propertyName = factory.createGeneratedPrivateNameForNode(property.name, '', accessorStorageSuffix);
|
|
1782
|
+
else if (propertyName instanceof ComputedPropertyName && !isSimpleInlineableExpression(propertyName.expression))
|
|
1783
|
+
propertyName = factory.updateComputedPropertyName(propertyName, factory.createGeneratedNameForNode(propertyName, 0, '', ''));
|
|
1784
|
+
if (hasStaticModifier(property))
|
|
1785
|
+
this.currentClassElement = property;
|
|
1786
|
+
if (propertyName instanceof PrivateIdentifier && this.shouldTransformClassElementToWeakMap(property)) {
|
|
1787
|
+
const info = this.accessPrivateIdentifier(propertyName);
|
|
1788
|
+
if (info === undefined)
|
|
1789
|
+
throw new Error('Undeclared private name for property declaration.');
|
|
1790
|
+
if (info.kind !== 0 /* PrivateKind.Field */)
|
|
1791
|
+
return undefined;
|
|
1792
|
+
const initializer = this.visitNode(property.initializer);
|
|
1793
|
+
const value = initializer !== undefined ? initializer : factory.createVoidZero();
|
|
1794
|
+
// `_C_x.set(this, value)`, or `_C_x = { value }` for statics.
|
|
1795
|
+
if (!info.isStatic)
|
|
1796
|
+
return factory.createMethodCall(info.brandCheckIdentifier, 'set', [receiver, value]);
|
|
1797
|
+
return factory.createAssignment(info.variableName, factory.createObjectLiteral([factory.createPropertyAssignment(factory.createIdentifier('value'), value)], false));
|
|
1798
|
+
}
|
|
1799
|
+
if ((propertyName instanceof PrivateIdentifier || hasStaticModifier(property)) &&
|
|
1800
|
+
property.initializer === undefined)
|
|
1801
|
+
return undefined;
|
|
1802
|
+
const original = context.mostOriginal(property);
|
|
1803
|
+
if (hasSyntacticModifier(original, 64 /* ModifierFlags.Abstract */))
|
|
1804
|
+
return undefined;
|
|
1805
|
+
let initializer = this.visitNode(property.initializer);
|
|
1806
|
+
if (isParameterPropertyDeclaration(original, original.parent) && propertyName instanceof Identifier) {
|
|
1807
|
+
// A parameter property's value is its parameter; an initializer here only comes from decorators.
|
|
1808
|
+
const localName = factory.cloneIdentifier(propertyName);
|
|
1809
|
+
if (initializer !== undefined) {
|
|
1810
|
+
// Unwrap `(__runInitializers(this, _instanceExtraInitializers), void 0)`.
|
|
1811
|
+
if (initializer instanceof ParenthesizedExpression) {
|
|
1812
|
+
const inner = initializer.expression;
|
|
1813
|
+
if (inner instanceof BinaryExpression &&
|
|
1814
|
+
inner.operatorToken.kind === 27 /* SyntaxKind.CommaToken */ &&
|
|
1815
|
+
context.isCallToHelper(inner.left, '__runInitializers') &&
|
|
1816
|
+
inner.right instanceof VoidExpression &&
|
|
1817
|
+
inner.right.expression.kind === 8 /* SyntaxKind.NumericLiteral */)
|
|
1818
|
+
initializer = inner.left;
|
|
1819
|
+
}
|
|
1820
|
+
initializer = factory.inlineExpressions([initializer, localName]);
|
|
1821
|
+
}
|
|
1822
|
+
else
|
|
1823
|
+
initializer = localName;
|
|
1824
|
+
context.addEmitFlags(propertyName, 384 /* EmitFlags.NoComments */ | 12 /* EmitFlags.NoSourceMap */);
|
|
1825
|
+
const originalName = getName(original);
|
|
1826
|
+
context.setSourceMapRange(localName, originalName.pos, originalName.end);
|
|
1827
|
+
context.addEmitFlags(localName, 384 /* EmitFlags.NoComments */);
|
|
1828
|
+
}
|
|
1829
|
+
else if (initializer === undefined)
|
|
1830
|
+
initializer = factory.createVoidZero();
|
|
1831
|
+
if (emitAssignment || propertyName instanceof PrivateIdentifier) {
|
|
1832
|
+
const access = this.createMemberAccessForPropertyName(receiver, propertyName);
|
|
1833
|
+
context.addEmitFlags(access, 128 /* EmitFlags.NoLeadingComments */);
|
|
1834
|
+
return factory.createAssignment(access, initializer);
|
|
1835
|
+
}
|
|
1836
|
+
// useDefineForClassFields: `Object.defineProperty(this, "x", { ... })`
|
|
1837
|
+
let name = propertyName;
|
|
1838
|
+
if (propertyName instanceof ComputedPropertyName)
|
|
1839
|
+
name = propertyName.expression;
|
|
1840
|
+
else if (propertyName instanceof Identifier)
|
|
1841
|
+
name = factory.createStringLiteral(propertyName.text, 0 /* TokenFlags.None */);
|
|
1842
|
+
const descriptor = factory.createObjectLiteral([
|
|
1843
|
+
factory.createPropertyAssignment(factory.createIdentifier('enumerable'), factory.createTrue()),
|
|
1844
|
+
factory.createPropertyAssignment(factory.createIdentifier('configurable'), factory.createTrue()),
|
|
1845
|
+
factory.createPropertyAssignment(factory.createIdentifier('writable'), factory.createTrue()),
|
|
1846
|
+
factory.createPropertyAssignment(factory.createIdentifier('value'), initializer),
|
|
1847
|
+
], true);
|
|
1848
|
+
return factory.createObjectDefinePropertyCall(receiver, name, descriptor);
|
|
1849
|
+
}
|
|
1850
|
+
createMemberAccessForPropertyName(receiver, name) {
|
|
1851
|
+
const factory = this.factory;
|
|
1852
|
+
if (name instanceof ComputedPropertyName)
|
|
1853
|
+
return this.withRange(factory.createElementAccessExpression(receiver, name.expression), name);
|
|
1854
|
+
const access = name instanceof Identifier || name instanceof PrivateIdentifier
|
|
1855
|
+
? factory.createPropertyAccessExpression(receiver, name)
|
|
1856
|
+
: factory.createElementAccessExpression(receiver, name);
|
|
1857
|
+
this.context.setCommentRange(access, name.pos, name.end);
|
|
1858
|
+
this.context.setSourceMapRange(access, name.pos, name.end);
|
|
1859
|
+
this.context.addEmitFlags(access, 16 /* EmitFlags.NoNestedSourceMaps */);
|
|
1860
|
+
return access;
|
|
1861
|
+
}
|
|
1862
|
+
/** `_C_instances.add(this)` brands instances for private methods and accessors. */
|
|
1863
|
+
addInstanceMethodStatements(statements, methods, receiver) {
|
|
1864
|
+
if (!this.shouldTransformPrivateElementsOrClassStaticBlocks || methods.length === 0)
|
|
1865
|
+
return false;
|
|
1866
|
+
const weakSetName = this.getPrivateEnvironment().weakSetName;
|
|
1867
|
+
statements.push(this.factory.createExpressionStatement(this.factory.createMethodCall(weakSetName, 'add', [receiver])));
|
|
1868
|
+
return true;
|
|
1869
|
+
}
|
|
1870
|
+
visitInvalidSuperProperty(node) {
|
|
1871
|
+
const factory = this.factory;
|
|
1872
|
+
if (node instanceof PropertyAccessExpression)
|
|
1873
|
+
return factory.updatePropertyAccessExpression(node, factory.createVoidZero(), undefined, node.name, node.flags);
|
|
1874
|
+
const access = node;
|
|
1875
|
+
return factory.updateElementAccessExpression(access, factory.createVoidZero(), undefined, this.visitNode(access.argumentExpression), access.flags);
|
|
1876
|
+
}
|
|
1877
|
+
/**
|
|
1878
|
+
* A visited computed name: an assignment caching its value when it's needed again (`shouldHoist`),
|
|
1879
|
+
* the expression when it has effects, or undefined when it's unused or safe to repeat.
|
|
1880
|
+
*/
|
|
1881
|
+
getPropertyNameExpressionIfNeeded(name, shouldHoist) {
|
|
1882
|
+
if (!(name instanceof ComputedPropertyName))
|
|
1883
|
+
return undefined;
|
|
1884
|
+
const cacheAssignment = findComputedPropertyNameCacheAssignment(name);
|
|
1885
|
+
const expression = this.visitInOuterEnvironment(name.expression);
|
|
1886
|
+
const inner = skipOuterExpressions(expression, 8 /* OuterExpressionKinds.PartiallyEmittedExpressions */);
|
|
1887
|
+
const inlinable = isSimpleInlineableExpression(inner);
|
|
1888
|
+
const alreadyTransformed = cacheAssignment !== undefined ||
|
|
1889
|
+
(inner instanceof BinaryExpression &&
|
|
1890
|
+
isAssignmentExpression(inner, true) &&
|
|
1891
|
+
inner.left instanceof Identifier &&
|
|
1892
|
+
this.context.hasAutoGenerateInfo(inner.left));
|
|
1893
|
+
if (!alreadyTransformed && !inlinable && shouldHoist) {
|
|
1894
|
+
const generated = this.addHoisted(this.factory.createGeneratedNameForNode(name, 0, '', ''), this.requiresBlockScopedVar());
|
|
1895
|
+
return this.factory.createAssignment(generated, expression);
|
|
1896
|
+
}
|
|
1897
|
+
if (inlinable || inner instanceof Identifier)
|
|
1898
|
+
return undefined;
|
|
1899
|
+
return expression;
|
|
1900
|
+
}
|
|
1901
|
+
getClassData() {
|
|
1902
|
+
const environment = this.lexicalEnvironment;
|
|
1903
|
+
if (environment.data === undefined)
|
|
1904
|
+
environment.data = new ClassData();
|
|
1905
|
+
return environment.data;
|
|
1906
|
+
}
|
|
1907
|
+
getPrivateEnvironment() {
|
|
1908
|
+
const environment = this.lexicalEnvironment;
|
|
1909
|
+
if (environment.privateEnv === undefined)
|
|
1910
|
+
environment.privateEnv = new PrivateEnvironment();
|
|
1911
|
+
return environment.privateEnv;
|
|
1912
|
+
}
|
|
1913
|
+
/** The brand check of a static member: the class, or its classThis. */
|
|
1914
|
+
staticBrandCheck() {
|
|
1915
|
+
const data = this.getClassData();
|
|
1916
|
+
return data.classThis !== undefined ? data.classThis : data.classConstructor;
|
|
1917
|
+
}
|
|
1918
|
+
addPrivateIdentifierPropertyDeclarationToEnvironment(node, name) {
|
|
1919
|
+
const environment = this.getPrivateEnvironment();
|
|
1920
|
+
const isStaticMember = hasStaticModifier(node);
|
|
1921
|
+
const isValid = !this.isReservedPrivateName(name) && this.getPrivateIdentifier(environment, name) === undefined;
|
|
1922
|
+
if (isStaticMember) {
|
|
1923
|
+
const info = new PrivateIdentifierInfo(0 /* PrivateKind.Field */, this.staticBrandCheck(), true, isValid);
|
|
1924
|
+
info.variableName = this.createHoistedVariableForPrivateName(name, '');
|
|
1925
|
+
this.setPrivateIdentifier(environment, name, info);
|
|
1926
|
+
return true;
|
|
1927
|
+
}
|
|
1928
|
+
const weakMapName = this.createHoistedVariableForPrivateName(name, '');
|
|
1929
|
+
this.setPrivateIdentifier(environment, name, new PrivateIdentifierInfo(0 /* PrivateKind.Field */, weakMapName, false, isValid));
|
|
1930
|
+
const factory = this.factory;
|
|
1931
|
+
this.pendingExpressions.push(factory.createAssignment(weakMapName, factory.created(new NewExpression(factory.createIdentifier('WeakMap'), undefined, factory.createNodeList([])))));
|
|
1932
|
+
return true;
|
|
1933
|
+
}
|
|
1934
|
+
addPrivateIdentifierToEnvironment(node) {
|
|
1935
|
+
const environment = this.getPrivateEnvironment();
|
|
1936
|
+
const name = getName(node);
|
|
1937
|
+
const isStaticMember = hasStaticModifier(node);
|
|
1938
|
+
const previous = this.getPrivateIdentifier(environment, name);
|
|
1939
|
+
const isValid = !this.isReservedPrivateName(name) && previous === undefined;
|
|
1940
|
+
if (node instanceof PropertyDeclaration && !isAutoAccessorPropertyDeclaration(node))
|
|
1941
|
+
return this.addPrivateIdentifierPropertyDeclarationToEnvironment(node, name);
|
|
1942
|
+
const brandCheck = isStaticMember ? this.staticBrandCheck() : environment.weakSetName;
|
|
1943
|
+
if (brandCheck === undefined)
|
|
1944
|
+
throw new Error(isStaticMember ? 'classConstructor should be set' : 'weakSetName should be set');
|
|
1945
|
+
if (node instanceof PropertyDeclaration) {
|
|
1946
|
+
const info = new PrivateIdentifierInfo(2 /* PrivateKind.Accessor */, brandCheck, isStaticMember, isValid);
|
|
1947
|
+
info.getterName = this.createHoistedVariableForPrivateName(name, '_get');
|
|
1948
|
+
info.setterName = this.createHoistedVariableForPrivateName(name, '_set');
|
|
1949
|
+
this.setPrivateIdentifier(environment, name, info);
|
|
1950
|
+
}
|
|
1951
|
+
else if (node.kind === 175 /* SyntaxKind.MethodDeclaration */) {
|
|
1952
|
+
const methodName = this.createHoistedVariableForPrivateName(name, '');
|
|
1953
|
+
const info = new PrivateIdentifierInfo(1 /* PrivateKind.Method */, brandCheck, isStaticMember, isValid);
|
|
1954
|
+
info.methodName = methodName;
|
|
1955
|
+
this.setPrivateIdentifier(environment, name, info);
|
|
1956
|
+
}
|
|
1957
|
+
else {
|
|
1958
|
+
const getter = node.kind === 178 /* SyntaxKind.GetAccessor */;
|
|
1959
|
+
const accessorName = this.createHoistedVariableForPrivateName(name, getter ? '_get' : '_set');
|
|
1960
|
+
// A get and set accessor pair shares one entry.
|
|
1961
|
+
if (previous !== undefined &&
|
|
1962
|
+
previous.kind === 2 /* PrivateKind.Accessor */ &&
|
|
1963
|
+
previous.isStatic === isStaticMember &&
|
|
1964
|
+
(getter ? previous.getterName === undefined : previous.setterName === undefined)) {
|
|
1965
|
+
if (getter)
|
|
1966
|
+
previous.getterName = accessorName;
|
|
1967
|
+
else
|
|
1968
|
+
previous.setterName = accessorName;
|
|
1969
|
+
}
|
|
1970
|
+
else {
|
|
1971
|
+
const info = new PrivateIdentifierInfo(2 /* PrivateKind.Accessor */, brandCheck, isStaticMember, isValid);
|
|
1972
|
+
if (getter)
|
|
1973
|
+
info.getterName = accessorName;
|
|
1974
|
+
else
|
|
1975
|
+
info.setterName = accessorName;
|
|
1976
|
+
this.setPrivateIdentifier(environment, name, info);
|
|
1977
|
+
}
|
|
1978
|
+
}
|
|
1979
|
+
return true;
|
|
1980
|
+
}
|
|
1981
|
+
setPrivateIdentifier(environment, name, info) {
|
|
1982
|
+
if (this.context.hasAutoGenerateInfo(name))
|
|
1983
|
+
environment.generated.set(this.context.getNodeForGeneratedName(name), info);
|
|
1984
|
+
else
|
|
1985
|
+
environment.members.set(privateNameText(name), info);
|
|
1986
|
+
return true;
|
|
1987
|
+
}
|
|
1988
|
+
getPrivateIdentifier(environment, name) {
|
|
1989
|
+
if (this.context.hasAutoGenerateInfo(name))
|
|
1990
|
+
return environment.generated.get(this.context.getNodeForGeneratedName(name));
|
|
1991
|
+
return environment.members.get(privateNameText(name));
|
|
1992
|
+
}
|
|
1993
|
+
/** A hoisted variable such as `_C_x`, prefixed with the class name when it has one. */
|
|
1994
|
+
createHoistedVariableForClass(text, node, suffix) {
|
|
1995
|
+
const className = this.getPrivateEnvironment().className;
|
|
1996
|
+
const prefix = className !== undefined ? '_' + className.text + '_' : '_';
|
|
1997
|
+
const identifier = this.factory.createUniqueNameWithSuffix(prefix + text, 16 /* GeneratedIdentifierFlags.Optimistic */ | 8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */, suffix);
|
|
1998
|
+
return this.addHoisted(identifier, this.requiresBlockScopedVar());
|
|
1999
|
+
}
|
|
2000
|
+
createHoistedVariableForPrivateName(name, suffix) {
|
|
2001
|
+
// Generated names, as of auto-accessor storage, are named from their node when printed.
|
|
2002
|
+
if (this.context.hasAutoGenerateInfo(name)) {
|
|
2003
|
+
const className = this.getPrivateEnvironment().className;
|
|
2004
|
+
const prefix = className !== undefined ? '_' + className.text + '_' : '_';
|
|
2005
|
+
const identifier = this.factory.createGeneratedNameForNode(name, 16 /* GeneratedIdentifierFlags.Optimistic */ | 8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */, prefix, suffix);
|
|
2006
|
+
return this.addHoisted(identifier, this.requiresBlockScopedVar());
|
|
2007
|
+
}
|
|
2008
|
+
let text = privateNameText(name);
|
|
2009
|
+
if (text.length > 0 && text.charCodeAt(0) === 0x23)
|
|
2010
|
+
text = text.slice(1);
|
|
2011
|
+
return this.createHoistedVariableForClass(text, name, suffix);
|
|
2012
|
+
}
|
|
2013
|
+
/** What a private name declared in this or an enclosing class transforms to. */
|
|
2014
|
+
accessPrivateIdentifier(name) {
|
|
2015
|
+
for (let environment = this.lexicalEnvironment; environment !== undefined; environment = environment.previous) {
|
|
2016
|
+
const privateEnv = environment.privateEnv;
|
|
2017
|
+
if (privateEnv === undefined)
|
|
2018
|
+
continue;
|
|
2019
|
+
const info = this.getPrivateIdentifier(privateEnv, name);
|
|
2020
|
+
if (info !== undefined)
|
|
2021
|
+
return info.kind === 3 /* PrivateKind.Untransformed */ ? undefined : info;
|
|
2022
|
+
}
|
|
2023
|
+
return undefined;
|
|
2024
|
+
}
|
|
2025
|
+
isReservedPrivateName(node) {
|
|
2026
|
+
if (node instanceof PrivateIdentifier && this.context.hasAutoGenerateInfo(node))
|
|
2027
|
+
return false;
|
|
2028
|
+
return privateNameText(node) === '#constructor';
|
|
2029
|
+
}
|
|
2030
|
+
/** `obj.#x` as a destructuring target: `({ set value(_a) { __classPrivateFieldSet(obj, ...); } }).value`. */
|
|
2031
|
+
wrapPrivateIdentifierForDestructuringTarget(node) {
|
|
2032
|
+
const factory = this.factory;
|
|
2033
|
+
const parameter = factory.createGeneratedNameForNode(node, 0, '', '');
|
|
2034
|
+
const info = this.accessPrivateIdentifier(node.name);
|
|
2035
|
+
if (info === undefined)
|
|
2036
|
+
return this.visitEachChild(node);
|
|
2037
|
+
let receiver = node.expression;
|
|
2038
|
+
// `this` and `super` would bind differently in the setter.
|
|
2039
|
+
const kind = node.expression.kind;
|
|
2040
|
+
if (kind === 109 /* SyntaxKind.ThisKeyword */ || kind === 107 /* SyntaxKind.SuperKeyword */ || !isSimpleCopiableExpression(receiver)) {
|
|
2041
|
+
const temp = this.context.addVariableDeclaration(factory.createTempVariable(8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */));
|
|
2042
|
+
this.pendingExpressions.push(factory.createAssignment(temp, this.visitNode(node.expression)));
|
|
2043
|
+
receiver = temp;
|
|
2044
|
+
}
|
|
2045
|
+
return factory.createAssignmentTargetWrapper(parameter, this.createPrivateIdentifierAssignment(info, receiver, parameter, 63 /* SyntaxKind.EqualsToken */));
|
|
2046
|
+
}
|
|
2047
|
+
visitDestructuringAssignmentTarget(node) {
|
|
2048
|
+
if (node instanceof ObjectLiteralExpression || node instanceof ArrayLiteralExpression)
|
|
2049
|
+
return this.visitAssignmentPattern(node);
|
|
2050
|
+
if (node instanceof PropertyAccessExpression && node.name instanceof PrivateIdentifier)
|
|
2051
|
+
return this.wrapPrivateIdentifierForDestructuringTarget(node);
|
|
2052
|
+
const data = this.staticSuperData(node);
|
|
2053
|
+
if (data !== undefined) {
|
|
2054
|
+
if ((data.facts & 1 /* ClassFacts.ClassWasDecorated */) !== 0)
|
|
2055
|
+
return this.visitInvalidSuperProperty(node);
|
|
2056
|
+
if (data.classConstructor !== undefined && data.superClassReference !== undefined) {
|
|
2057
|
+
let name = undefined;
|
|
2058
|
+
if (node instanceof ElementAccessExpression)
|
|
2059
|
+
name = this.visitNode(node.argumentExpression);
|
|
2060
|
+
else if (node instanceof PropertyAccessExpression && node.name instanceof Identifier)
|
|
2061
|
+
name = this.factory.createStringLiteralFromNode(node.name);
|
|
2062
|
+
if (name !== undefined) {
|
|
2063
|
+
const temp = this.factory.createTempVariable(0);
|
|
2064
|
+
return this.factory.createAssignmentTargetWrapper(temp, this.factory.createReflectSetCall(data.superClassReference, name, temp, data.classConstructor));
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
return this.visitEachChild(node);
|
|
2069
|
+
}
|
|
2070
|
+
visitAssignmentElement(element) {
|
|
2071
|
+
const node = this.transformNamedEvaluationIfNeeded(element, '');
|
|
2072
|
+
if (node instanceof BinaryExpression && isAssignmentExpression(node, true)) {
|
|
2073
|
+
const left = this.visitDestructuringAssignmentTarget(node.left);
|
|
2074
|
+
const right = this.visitNode(node.right);
|
|
2075
|
+
return this.factory.updateBinaryExpression(node, undefined, left, undefined, node.operatorToken, right);
|
|
2076
|
+
}
|
|
2077
|
+
return this.visitDestructuringAssignmentTarget(node);
|
|
2078
|
+
}
|
|
2079
|
+
visitArrayAssignmentElement(node) {
|
|
2080
|
+
if (isArrayBindingOrAssignmentElement(node)) {
|
|
2081
|
+
if (node instanceof SpreadElement) {
|
|
2082
|
+
if (isLeftHandSideExpression(node.expression))
|
|
2083
|
+
return this.factory.updateSpreadElement(node, this.visitDestructuringAssignmentTarget(node.expression));
|
|
2084
|
+
return this.visitEachChild(node);
|
|
2085
|
+
}
|
|
2086
|
+
if (node.kind !== 233 /* SyntaxKind.OmittedExpression */)
|
|
2087
|
+
return this.visitAssignmentElement(node);
|
|
2088
|
+
}
|
|
2089
|
+
return this.visitEachChild(node);
|
|
2090
|
+
}
|
|
2091
|
+
visitObjectAssignmentElement(node) {
|
|
2092
|
+
const factory = this.factory;
|
|
2093
|
+
if (node instanceof SpreadAssignment) {
|
|
2094
|
+
if (isLeftHandSideExpression(node.expression))
|
|
2095
|
+
return factory.updateSpreadAssignment(node, this.visitDestructuringAssignmentTarget(node.expression));
|
|
2096
|
+
return this.visitEachChild(node);
|
|
2097
|
+
}
|
|
2098
|
+
if (node instanceof ShorthandPropertyAssignment)
|
|
2099
|
+
return this.visitEachChild(this.transformNamedEvaluationIfNeeded(node, ''));
|
|
2100
|
+
if (node instanceof PropertyAssignment) {
|
|
2101
|
+
const name = this.visitNode(node.name);
|
|
2102
|
+
const initializer = node.initializer;
|
|
2103
|
+
if (initializer instanceof BinaryExpression && isAssignmentExpression(initializer, true))
|
|
2104
|
+
return factory.updatePropertyAssignment(node, undefined, name, undefined, undefined, this.visitAssignmentElement(initializer));
|
|
2105
|
+
if (isLeftHandSideExpression(initializer))
|
|
2106
|
+
return factory.updatePropertyAssignment(node, undefined, name, undefined, undefined, this.visitDestructuringAssignmentTarget(initializer));
|
|
2107
|
+
return this.visitEachChild(node);
|
|
2108
|
+
}
|
|
2109
|
+
return this.visitEachChild(node);
|
|
2110
|
+
}
|
|
2111
|
+
/** Private names and static `super` in destructuring targets, as `[{ set value(x) { ... } }.value] = ...`. */
|
|
2112
|
+
visitAssignmentPattern(node) {
|
|
2113
|
+
if (node instanceof ArrayLiteralExpression)
|
|
2114
|
+
return this.factory.updateArrayLiteralExpression(node, this.arrayElementMode.visitNodes(node.elements), node.multiLine);
|
|
2115
|
+
const object = node;
|
|
2116
|
+
return this.factory.updateObjectLiteralExpression(object, this.objectElementMode.visitNodes(object.properties), object.multiLine);
|
|
2117
|
+
}
|
|
2118
|
+
createAccessorPropertyGetRedirector(node, modifiers, name, receiver) {
|
|
2119
|
+
const factory = this.factory;
|
|
2120
|
+
const storage = factory.createGeneratedPrivateNameForNode(node.name, '', accessorStorageSuffix);
|
|
2121
|
+
const body = factory.createBlock([factory.createReturnStatement(factory.createPropertyAccessExpression(receiver, storage))], false);
|
|
2122
|
+
return factory.created(new GetAccessorDeclaration(modifiers, name, undefined, factory.createNodeList([]), undefined, undefined, body));
|
|
2123
|
+
}
|
|
2124
|
+
createAccessorPropertySetRedirector(node, modifiers, name, receiver) {
|
|
2125
|
+
const factory = this.factory;
|
|
2126
|
+
const storage = factory.createGeneratedPrivateNameForNode(node.name, '', accessorStorageSuffix);
|
|
2127
|
+
const assignment = factory.createAssignment(factory.createPropertyAccessExpression(receiver, storage), factory.createIdentifier('value'));
|
|
2128
|
+
const body = factory.createBlock([factory.createExpressionStatement(assignment)], false);
|
|
2129
|
+
const parameters = factory.createNodeList([factory.createParameter(factory.createIdentifier('value'))]);
|
|
2130
|
+
return factory.created(new SetAccessorDeclaration(modifiers, name, undefined, parameters, undefined, undefined, body));
|
|
2131
|
+
}
|
|
2132
|
+
createCallBinding(node) {
|
|
2133
|
+
const factory = this.factory;
|
|
2134
|
+
if (isSuperProperty(node))
|
|
2135
|
+
return new CallBinding(factory.createThisExpression(), node);
|
|
2136
|
+
if (node instanceof PropertyAccessExpression) {
|
|
2137
|
+
if (!shouldBeCapturedInTempVariable(node.expression))
|
|
2138
|
+
return new CallBinding(node.expression, node);
|
|
2139
|
+
const thisArg = this.context.addVariableDeclaration(factory.createTempVariable(0));
|
|
2140
|
+
const target = factory.createPropertyAccessExpression(factory.createParenthesizedExpression(factory.createAssignment(thisArg, node.expression)), node.name);
|
|
2141
|
+
return new CallBinding(thisArg, target);
|
|
2142
|
+
}
|
|
2143
|
+
return new CallBinding(factory.createVoidZero(), node);
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
/** Finds identifiers in member code that resolve to a class, skipping property names. */
|
|
2147
|
+
class ConstructorReferenceFinder extends NodeVisitor {
|
|
2148
|
+
resolver;
|
|
2149
|
+
classOriginal;
|
|
2150
|
+
className;
|
|
2151
|
+
constructor(resolver, classOriginal, className) {
|
|
2152
|
+
super();
|
|
2153
|
+
this.resolver = resolver;
|
|
2154
|
+
this.classOriginal = classOriginal;
|
|
2155
|
+
this.className = className;
|
|
2156
|
+
}
|
|
2157
|
+
check(node) {
|
|
2158
|
+
if (node instanceof Identifier && !isSameNode(node, this.className)) {
|
|
2159
|
+
const declaration = this.resolver.getReferencedValueDeclaration(node);
|
|
2160
|
+
if (declaration !== undefined && declaration === this.classOriginal)
|
|
2161
|
+
return true;
|
|
2162
|
+
}
|
|
2163
|
+
if (node instanceof PropertyAccessExpression)
|
|
2164
|
+
return this.check(node.expression);
|
|
2165
|
+
return node.forEachChild(this);
|
|
2166
|
+
}
|
|
2167
|
+
visitNode(node) {
|
|
2168
|
+
return this.check(node);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
function membersOf(node) {
|
|
2172
|
+
const members = getMembers(node);
|
|
2173
|
+
return members === undefined ? [] : members.nodes;
|
|
2174
|
+
}
|
|
2175
|
+
function parametersOf(node) {
|
|
2176
|
+
const parameters = getParameters(node);
|
|
2177
|
+
return parameters !== undefined ? parameters : new NodeList(-1, -1, []);
|
|
2178
|
+
}
|
|
2179
|
+
function appendAll(target, source) {
|
|
2180
|
+
for (let i = 0; i < source.length; i++)
|
|
2181
|
+
target.push(source[i]);
|
|
2182
|
+
return true;
|
|
2183
|
+
}
|
|
2184
|
+
function classThisOf(context, node) {
|
|
2185
|
+
const classThis = context.getClassThis(node);
|
|
2186
|
+
return classThis instanceof Identifier ? classThis : undefined;
|
|
2187
|
+
}
|
|
2188
|
+
function privateNameText(node) {
|
|
2189
|
+
if (node instanceof PrivateIdentifier)
|
|
2190
|
+
return node.text;
|
|
2191
|
+
if (node instanceof Identifier)
|
|
2192
|
+
return node.text;
|
|
2193
|
+
return '';
|
|
2194
|
+
}
|
|
2195
|
+
function isInitializedProperty(node) {
|
|
2196
|
+
return node instanceof PropertyDeclaration && node.initializer !== undefined;
|
|
2197
|
+
}
|
|
2198
|
+
function isSuperProperty(node) {
|
|
2199
|
+
if (node instanceof PropertyAccessExpression)
|
|
2200
|
+
return node.expression.kind === 107 /* SyntaxKind.SuperKeyword */;
|
|
2201
|
+
if (node instanceof ElementAccessExpression)
|
|
2202
|
+
return node.expression.kind === 107 /* SyntaxKind.SuperKeyword */;
|
|
2203
|
+
return false;
|
|
2204
|
+
}
|
|
2205
|
+
function isStaticPropertyDeclarationOrClassStaticBlock(node) {
|
|
2206
|
+
return (node.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */ ||
|
|
2207
|
+
(node.kind === 173 /* SyntaxKind.PropertyDeclaration */ && hasStaticModifier(node)));
|
|
2208
|
+
}
|
|
2209
|
+
function isCompoundAssignment(kind) {
|
|
2210
|
+
return kind >= 64 /* SyntaxKind.FirstCompoundAssignment */ && kind <= 78 /* SyntaxKind.LastCompoundAssignment */;
|
|
2211
|
+
}
|
|
2212
|
+
function nonAssignmentOperatorForCompoundAssignment(kind) {
|
|
2213
|
+
switch (kind) {
|
|
2214
|
+
case 64 /* SyntaxKind.PlusEqualsToken */:
|
|
2215
|
+
return 39 /* SyntaxKind.PlusToken */;
|
|
2216
|
+
case 65 /* SyntaxKind.MinusEqualsToken */:
|
|
2217
|
+
return 40 /* SyntaxKind.MinusToken */;
|
|
2218
|
+
case 66 /* SyntaxKind.AsteriskEqualsToken */:
|
|
2219
|
+
return 41 /* SyntaxKind.AsteriskToken */;
|
|
2220
|
+
case 67 /* SyntaxKind.AsteriskAsteriskEqualsToken */:
|
|
2221
|
+
return 42 /* SyntaxKind.AsteriskAsteriskToken */;
|
|
2222
|
+
case 68 /* SyntaxKind.SlashEqualsToken */:
|
|
2223
|
+
return 43 /* SyntaxKind.SlashToken */;
|
|
2224
|
+
case 69 /* SyntaxKind.PercentEqualsToken */:
|
|
2225
|
+
return 44 /* SyntaxKind.PercentToken */;
|
|
2226
|
+
case 70 /* SyntaxKind.LessThanLessThanEqualsToken */:
|
|
2227
|
+
return 47 /* SyntaxKind.LessThanLessThanToken */;
|
|
2228
|
+
case 71 /* SyntaxKind.GreaterThanGreaterThanEqualsToken */:
|
|
2229
|
+
return 48 /* SyntaxKind.GreaterThanGreaterThanToken */;
|
|
2230
|
+
case 72 /* SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken */:
|
|
2231
|
+
return 49 /* SyntaxKind.GreaterThanGreaterThanGreaterThanToken */;
|
|
2232
|
+
case 73 /* SyntaxKind.AmpersandEqualsToken */:
|
|
2233
|
+
return 50 /* SyntaxKind.AmpersandToken */;
|
|
2234
|
+
case 74 /* SyntaxKind.BarEqualsToken */:
|
|
2235
|
+
return 51 /* SyntaxKind.BarToken */;
|
|
2236
|
+
case 78 /* SyntaxKind.CaretEqualsToken */:
|
|
2237
|
+
return 52 /* SyntaxKind.CaretToken */;
|
|
2238
|
+
case 75 /* SyntaxKind.BarBarEqualsToken */:
|
|
2239
|
+
return 56 /* SyntaxKind.BarBarToken */;
|
|
2240
|
+
case 76 /* SyntaxKind.AmpersandAmpersandEqualsToken */:
|
|
2241
|
+
return 55 /* SyntaxKind.AmpersandAmpersandToken */;
|
|
2242
|
+
case 77 /* SyntaxKind.QuestionQuestionEqualsToken */:
|
|
2243
|
+
return 60 /* SyntaxKind.QuestionQuestionToken */;
|
|
2244
|
+
}
|
|
2245
|
+
return 0 /* SyntaxKind.Unknown */;
|
|
2246
|
+
}
|
|
2247
|
+
function isSimpleCopiableExpression(node) {
|
|
2248
|
+
switch (node.kind) {
|
|
2249
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
2250
|
+
case 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */:
|
|
2251
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
2252
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
2253
|
+
return true;
|
|
2254
|
+
}
|
|
2255
|
+
return node.kind >= 82 /* SyntaxKind.FirstKeyword */ && node.kind <= 166 /* SyntaxKind.LastKeyword */;
|
|
2256
|
+
}
|
|
2257
|
+
/** A literal or keyword that can be repeated; identifiers may be reassigned in between. */
|
|
2258
|
+
function isSimpleInlineableExpression(node) {
|
|
2259
|
+
return node.kind !== 79 /* SyntaxKind.Identifier */ && isSimpleCopiableExpression(node);
|
|
2260
|
+
}
|
|
2261
|
+
function shouldBeCapturedInTempVariable(node) {
|
|
2262
|
+
switch (skipParentheses(node).kind) {
|
|
2263
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
2264
|
+
case 109 /* SyntaxKind.ThisKeyword */:
|
|
2265
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
2266
|
+
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
2267
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
2268
|
+
return false;
|
|
2269
|
+
}
|
|
2270
|
+
return true;
|
|
2271
|
+
}
|
|
2272
|
+
function isArrayBindingOrAssignmentElement(node) {
|
|
2273
|
+
switch (node.kind) {
|
|
2274
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
2275
|
+
case 233 /* SyntaxKind.OmittedExpression */:
|
|
2276
|
+
case 231 /* SyntaxKind.SpreadElement */:
|
|
2277
|
+
case 210 /* SyntaxKind.ArrayLiteralExpression */:
|
|
2278
|
+
case 211 /* SyntaxKind.ObjectLiteralExpression */:
|
|
2279
|
+
case 79 /* SyntaxKind.Identifier */:
|
|
2280
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
2281
|
+
case 213 /* SyntaxKind.ElementAccessExpression */:
|
|
2282
|
+
return true;
|
|
2283
|
+
}
|
|
2284
|
+
return isAssignmentExpression(node, true);
|
|
2285
|
+
}
|
|
2286
|
+
function staticPropertiesAndClassStaticBlocks(node) {
|
|
2287
|
+
const result = [];
|
|
2288
|
+
const members = membersOf(node);
|
|
2289
|
+
for (let i = 0; i < members.length; i++) {
|
|
2290
|
+
const member = members[i];
|
|
2291
|
+
if (member.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */ ||
|
|
2292
|
+
(member.kind === 173 /* SyntaxKind.PropertyDeclaration */ && hasStaticModifier(member)))
|
|
2293
|
+
result.push(member);
|
|
2294
|
+
}
|
|
2295
|
+
return result;
|
|
2296
|
+
}
|
|
2297
|
+
function propertiesOf(node, isStaticProperty) {
|
|
2298
|
+
const result = [];
|
|
2299
|
+
const members = membersOf(node);
|
|
2300
|
+
for (let i = 0; i < members.length; i++)
|
|
2301
|
+
if (members[i] instanceof PropertyDeclaration && hasStaticModifier(members[i]) === isStaticProperty)
|
|
2302
|
+
result.push(members[i]);
|
|
2303
|
+
return result;
|
|
2304
|
+
}
|
|
2305
|
+
function privateInstanceMethodsAndAccessors(node) {
|
|
2306
|
+
const result = [];
|
|
2307
|
+
const members = membersOf(node);
|
|
2308
|
+
for (let i = 0; i < members.length; i++) {
|
|
2309
|
+
const member = members[i];
|
|
2310
|
+
if (!isStatic(member) &&
|
|
2311
|
+
(isMethodOrAccessor(member) || isAutoAccessorPropertyDeclaration(member)) &&
|
|
2312
|
+
getName(member).kind === 80 /* SyntaxKind.PrivateIdentifier */)
|
|
2313
|
+
result.push(member);
|
|
2314
|
+
}
|
|
2315
|
+
return result;
|
|
2316
|
+
}
|
|
2317
|
+
function getClassExtendsHeritageElement(node) {
|
|
2318
|
+
let clauses = undefined;
|
|
2319
|
+
if (node instanceof ClassDeclaration)
|
|
2320
|
+
clauses = node.heritageClauses;
|
|
2321
|
+
else if (node instanceof ClassExpression)
|
|
2322
|
+
clauses = node.heritageClauses;
|
|
2323
|
+
if (clauses === undefined)
|
|
2324
|
+
return undefined;
|
|
2325
|
+
for (let i = 0; i < clauses.nodes.length; i++) {
|
|
2326
|
+
const clause = clauses.nodes[i];
|
|
2327
|
+
if (clause instanceof HeritageClause && clause.token === 95 /* SyntaxKind.ExtendsKeyword */) {
|
|
2328
|
+
const first = clause.types.nodes[0];
|
|
2329
|
+
return first instanceof ExpressionWithTypeArguments ? first : undefined;
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
return undefined;
|
|
2333
|
+
}
|
|
2334
|
+
/** Whether a class or its constructor's parameters have decorators that apply. */
|
|
2335
|
+
function classOrConstructorParameterIsDecorated(legacy, node) {
|
|
2336
|
+
if (hasDecorators(node) && (node.kind === 264 /* SyntaxKind.ClassDeclaration */ || !legacy))
|
|
2337
|
+
return true;
|
|
2338
|
+
if (!legacy)
|
|
2339
|
+
return false;
|
|
2340
|
+
const members = membersOf(node);
|
|
2341
|
+
for (let i = 0; i < members.length; i++) {
|
|
2342
|
+
const member = members[i];
|
|
2343
|
+
if (!(member instanceof ConstructorDeclaration) || member.body === undefined)
|
|
2344
|
+
continue;
|
|
2345
|
+
const parameters = member.parameters.nodes;
|
|
2346
|
+
for (let j = 0; j < parameters.length; j++)
|
|
2347
|
+
if (hasDecorators(parameters[j]))
|
|
2348
|
+
return true;
|
|
2349
|
+
return false;
|
|
2350
|
+
}
|
|
2351
|
+
return false;
|
|
2352
|
+
}
|
|
2353
|
+
/** The `_a = ...` assignment caching a computed name's value, at the end of its comma list. */
|
|
2354
|
+
function findComputedPropertyNameCacheAssignment(name) {
|
|
2355
|
+
let node = name.expression;
|
|
2356
|
+
for (;;) {
|
|
2357
|
+
node = skipOuterExpressions(node, 0 /* OuterExpressionKinds.None */);
|
|
2358
|
+
if (node instanceof BinaryExpression && node.operatorToken.kind === 27 /* SyntaxKind.CommaToken */) {
|
|
2359
|
+
node = node.right;
|
|
2360
|
+
continue;
|
|
2361
|
+
}
|
|
2362
|
+
if (node instanceof BinaryExpression && isAssignmentExpression(node, true) && node.left instanceof Identifier)
|
|
2363
|
+
return node;
|
|
2364
|
+
return undefined;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
/** The expressions of a comma list, appended to `out`. */
|
|
2368
|
+
function flattenCommaList(node, out) {
|
|
2369
|
+
if (node instanceof ParenthesizedExpression && nodeIsSynthesized(node))
|
|
2370
|
+
return flattenCommaList(node.expression, out);
|
|
2371
|
+
if (node instanceof BinaryExpression && node.operatorToken.kind === 27 /* SyntaxKind.CommaToken */) {
|
|
2372
|
+
flattenCommaList(node.left, out);
|
|
2373
|
+
return flattenCommaList(node.right, out);
|
|
2374
|
+
}
|
|
2375
|
+
out.push(node);
|
|
2376
|
+
return true;
|
|
2377
|
+
}
|
|
2378
|
+
/** The start of a member after its modifiers, or its decorators, for source maps. */
|
|
2379
|
+
function posPastModifiers(node) {
|
|
2380
|
+
if (node instanceof PropertyDeclaration)
|
|
2381
|
+
return node.name.pos;
|
|
2382
|
+
if (node instanceof MethodDeclaration)
|
|
2383
|
+
return node.name.pos;
|
|
2384
|
+
if (node.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */)
|
|
2385
|
+
return node.pos;
|
|
2386
|
+
const modifiers = getModifiers(node);
|
|
2387
|
+
if (modifiers === undefined || modifiers.nodes.length === 0)
|
|
2388
|
+
return node.pos;
|
|
2389
|
+
const last = modifiers.nodes[modifiers.nodes.length - 1];
|
|
2390
|
+
if (last.end >= 0)
|
|
2391
|
+
return last.end;
|
|
2392
|
+
for (let i = modifiers.nodes.length - 1; i >= 0; i--)
|
|
2393
|
+
if (modifiers.nodes[i].kind === 171 /* SyntaxKind.Decorator */)
|
|
2394
|
+
return modifiers.nodes[i].end >= 0 ? modifiers.nodes[i].end : node.pos;
|
|
2395
|
+
return node.pos;
|
|
2396
|
+
}
|
|
2397
|
+
/** Properties assigned in the constructor with useDefineForClassFields: false. */
|
|
2398
|
+
function withInitializerOrPrivateName(properties) {
|
|
2399
|
+
const result = [];
|
|
2400
|
+
for (let i = 0; i < properties.length; i++) {
|
|
2401
|
+
const property = properties[i];
|
|
2402
|
+
if (getInitializer(property) !== undefined ||
|
|
2403
|
+
getName(property).kind === 80 /* SyntaxKind.PrivateIdentifier */ ||
|
|
2404
|
+
hasSyntacticModifier(property, 512 /* ModifierFlags.Accessor */))
|
|
2405
|
+
result.push(property);
|
|
2406
|
+
}
|
|
2407
|
+
return result;
|
|
2408
|
+
}
|
|
2409
|
+
class ClassesNeedingNames extends AnonymousFunctionFilter {
|
|
2410
|
+
transformer;
|
|
2411
|
+
constructor(transformer) {
|
|
2412
|
+
super();
|
|
2413
|
+
this.transformer = transformer;
|
|
2414
|
+
}
|
|
2415
|
+
accepts(node) {
|
|
2416
|
+
return this.transformer.isAnonymousClassNeedingAssignedName(node);
|
|
2417
|
+
}
|
|
2418
|
+
}
|