tsc-ts 0.0.4 → 0.0.6
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 +34 -2
- 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 +2351 -0
- package/dist/api/compiler/ast.js +11212 -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 +1241 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2359 -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 +1641 -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 +357 -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 +788 -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 +314 -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 +291 -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 +580 -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 +2587 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +901 -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 +442 -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 +200 -0
- package/dist/api/compiler/checker-members.js +2148 -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 +483 -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 +271 -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 +789 -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 +51 -0
- package/dist/api/compiler/checker-symbol-types.js +955 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1784 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2542 -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 +1093 -0
- package/dist/api/compiler/checker-types.js +1874 -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 +512 -0
- package/dist/api/compiler/checker.js +932 -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 +161 -0
- package/dist/api/compiler/diagnostics.js +784 -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 +144 -0
- package/dist/api/compiler/file-include.js +599 -0
- package/dist/api/compiler/file-loader.d.ts +290 -0
- package/dist/api/compiler/file-loader.js +1323 -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 +835 -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 +105 -0
- package/dist/api/compiler/link-tables.js +319 -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 +745 -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 +221 -0
- package/dist/api/compiler/parallel-parse.js +541 -0
- package/dist/api/compiler/parser.d.ts +604 -0
- package/dist/api/compiler/parser.js +6426 -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 +157 -0
- package/dist/api/compiler/printer/emit-context.js +582 -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 +529 -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 +1019 -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 +991 -0
- package/dist/api/compiler/symbol.d.ts +282 -0
- package/dist/api/compiler/symbol.js +339 -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 +677 -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 +539 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +799 -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 +198 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2381 -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 +129 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1157 -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 +10 -0
- package/dist/api/compiler/transformers/subtree-facts.js +205 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +52 -0
- package/dist/api/compiler/transformers/syntax-facts.js +258 -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 +3 -2
- package/dist/api/library/ast.generated.d.ts +127 -139
- package/dist/api/library/checker.d.ts +51 -0
- package/dist/api/library/checker.js +318 -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/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 +5 -1
- package/dist/api/library/index.js +4 -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/types.d.ts +14 -1
- package/package.json +12 -8
- package/src/compiler/ast-utilities.ts +548 -0
- package/src/compiler/ast.ts +12870 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2707 -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 +1201 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +355 -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 +3596 -0
- package/src/compiler/checker-heritage.ts +1240 -0
- package/src/compiler/checker-inference.ts +2584 -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 +1928 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2480 -0
- package/src/compiler/checker-modules.ts +2896 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +591 -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 +1187 -0
- package/src/compiler/checker-symbols.ts +2157 -0
- package/src/compiler/checker-type-factory.ts +2616 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2510 -0
- package/src/compiler/checker-types.ts +2520 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1138 -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 +858 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +741 -0
- package/src/compiler/file-loader.ts +1597 -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 +2818 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +938 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +343 -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 +1071 -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 +3433 -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 +1954 -0
- package/src/compiler/parallel-parse.ts +595 -0
- package/src/compiler/parse-thread.ts +136 -0
- package/src/compiler/parser.ts +7766 -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 +684 -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 +594 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1426 -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 +1166 -0
- package/src/compiler/symbol.ts +557 -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 +833 -0
- package/src/compiler/transformers/declarations-pseudo.ts +969 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1867 -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 +1213 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +253 -0
- package/src/compiler/transformers/syntax-facts.ts +358 -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 +1422 -0
- package/src/compiler/tsc-cli.ts +669 -0
- package/src/compiler/tsc-compile.ts +446 -0
- package/src/compiler/tsc-watch.ts +922 -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 +141 -167
- package/src/library/ast.ts +4 -1
- package/src/library/checker.ts +384 -0
- package/src/library/diagnostics.ts +72 -0
- package/src/library/disk.ts +73 -0
- package/src/library/errors.ts +26 -0
- package/src/library/host.ts +63 -0
- package/src/library/index.ts +21 -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/types.ts +14 -1
|
@@ -0,0 +1,2682 @@
|
|
|
1
|
+
// Standard (TC39) decorators: decorated classes become an IIFE that applies `__esDecorate` to
|
|
2
|
+
// each decorated element and the class, and runs initializers with `__runInitializers`.
|
|
3
|
+
//
|
|
4
|
+
// Evaluation order: class decorators, then the heritage clause, then for each member its
|
|
5
|
+
// decorators and computed name; then static and instance method/accessor decorators, static and
|
|
6
|
+
// instance field decorators, class decorators; then static extra initializers, static fields and
|
|
7
|
+
// blocks, and class extra initializers. Constructors run instance extra initializers first, then
|
|
8
|
+
// each instance field's initializer and extra initializers.
|
|
9
|
+
import {
|
|
10
|
+
ArrayLiteralExpression,
|
|
11
|
+
BinaryExpression,
|
|
12
|
+
BindingElement,
|
|
13
|
+
Block,
|
|
14
|
+
CallExpression,
|
|
15
|
+
ClassDeclaration,
|
|
16
|
+
ClassExpression,
|
|
17
|
+
CatchClause,
|
|
18
|
+
ClassStaticBlockDeclaration,
|
|
19
|
+
ComputedPropertyName,
|
|
20
|
+
ConstructorDeclaration,
|
|
21
|
+
Decorator,
|
|
22
|
+
ElementAccessExpression,
|
|
23
|
+
ExportAssignment,
|
|
24
|
+
ExpressionStatement,
|
|
25
|
+
ExpressionWithTypeArguments,
|
|
26
|
+
ForStatement,
|
|
27
|
+
FunctionExpression,
|
|
28
|
+
GetAccessorDeclaration,
|
|
29
|
+
Identifier,
|
|
30
|
+
IfStatement,
|
|
31
|
+
MethodDeclaration,
|
|
32
|
+
ModifierFlags,
|
|
33
|
+
ModifierList,
|
|
34
|
+
type Node,
|
|
35
|
+
NodeFlags,
|
|
36
|
+
NodeList,
|
|
37
|
+
ObjectLiteralExpression,
|
|
38
|
+
ParameterDeclaration,
|
|
39
|
+
ParenthesizedExpression,
|
|
40
|
+
PartiallyEmittedExpression,
|
|
41
|
+
PostfixUnaryExpression,
|
|
42
|
+
PrefixUnaryExpression,
|
|
43
|
+
PrivateIdentifier,
|
|
44
|
+
PropertyAccessExpression,
|
|
45
|
+
PropertyAssignment,
|
|
46
|
+
PropertyDeclaration,
|
|
47
|
+
SetAccessorDeclaration,
|
|
48
|
+
ShorthandPropertyAssignment,
|
|
49
|
+
SourceFile,
|
|
50
|
+
SpreadAssignment,
|
|
51
|
+
SpreadElement,
|
|
52
|
+
StringLiteral,
|
|
53
|
+
SyntaxList,
|
|
54
|
+
TaggedTemplateExpression,
|
|
55
|
+
Token,
|
|
56
|
+
TryStatement,
|
|
57
|
+
VariableDeclaration,
|
|
58
|
+
VariableStatement,
|
|
59
|
+
getBody,
|
|
60
|
+
getModifiers,
|
|
61
|
+
getName,
|
|
62
|
+
getParameters,
|
|
63
|
+
} from '../ast.js';
|
|
64
|
+
import { isLeftHandSideExpression } from '../ast-utilities.js';
|
|
65
|
+
import {
|
|
66
|
+
hasSyntacticModifier,
|
|
67
|
+
hasStaticModifier,
|
|
68
|
+
isAssignmentExpression,
|
|
69
|
+
isAutoAccessorPropertyDeclaration,
|
|
70
|
+
isClassLike,
|
|
71
|
+
isDestructuringAssignment,
|
|
72
|
+
isMethodOrAccessor,
|
|
73
|
+
isPrivateIdentifierClassElementDeclaration,
|
|
74
|
+
isPropertyNameLiteral,
|
|
75
|
+
isStatic,
|
|
76
|
+
skipParentheses,
|
|
77
|
+
} from '../binder-utilities.js';
|
|
78
|
+
import { type CompilerOptions, ScriptTarget, getEmitScriptTarget, getUseDefineForClassFields } from '../options.js';
|
|
79
|
+
import {
|
|
80
|
+
createESDecorateHelper,
|
|
81
|
+
createPropKeyHelper,
|
|
82
|
+
createRunInitializersHelper,
|
|
83
|
+
createSetFunctionNameHelper,
|
|
84
|
+
} from '../printer/decorator-helpers.js';
|
|
85
|
+
import type { EmitContext } from '../printer/emit-context.js';
|
|
86
|
+
import { EmitFlags, GeneratedIdentifierFlags } from '../printer/emit-flags.js';
|
|
87
|
+
import { NameOptions } from '../printer/factory.js';
|
|
88
|
+
import { isIdentifierText } from '../scanner.js';
|
|
89
|
+
import { SyntaxKind } from '../syntax-kind.js';
|
|
90
|
+
import { TokenFlags } from '../types.js';
|
|
91
|
+
import {
|
|
92
|
+
countPrologueDirectives,
|
|
93
|
+
createAccessorPropertyBackingField,
|
|
94
|
+
createExportDefault,
|
|
95
|
+
createExternalModuleExport,
|
|
96
|
+
getClassHeritageClauses,
|
|
97
|
+
getClassMembers,
|
|
98
|
+
getClassName,
|
|
99
|
+
expandPreOrPostfixIncrementOrDecrementExpression,
|
|
100
|
+
findComputedPropertyNameCacheAssignment,
|
|
101
|
+
findSuperStatementIndexPath,
|
|
102
|
+
getHeritageClause,
|
|
103
|
+
getNonAssignmentOperatorForCompoundAssignment,
|
|
104
|
+
injectClassThisAssignmentIfMissing,
|
|
105
|
+
isClassThisAssignmentBlock,
|
|
106
|
+
isCompoundAssignment,
|
|
107
|
+
isSuperProperty,
|
|
108
|
+
} from './class-utilities.js';
|
|
109
|
+
import {
|
|
110
|
+
childIsDecorated,
|
|
111
|
+
classOrConstructorParameterIsDecorated,
|
|
112
|
+
getDecorators,
|
|
113
|
+
getFirstConstructorWithBody,
|
|
114
|
+
isSimpleInlineableExpression,
|
|
115
|
+
moveRangePastDecorators,
|
|
116
|
+
moveRangePastModifiers,
|
|
117
|
+
nodeIsDecorated,
|
|
118
|
+
nodeOrChildIsDecorated,
|
|
119
|
+
} from './decorator-utilities.js';
|
|
120
|
+
import {
|
|
121
|
+
AnonymousFunctionFilter,
|
|
122
|
+
classHasDeclaredOrExplicitlyAssignedName,
|
|
123
|
+
injectClassNamedEvaluationHelperBlockIfMissing,
|
|
124
|
+
isClassNamedEvaluationHelperBlock,
|
|
125
|
+
isNamedEvaluation,
|
|
126
|
+
transformNamedEvaluation,
|
|
127
|
+
} from './named-evaluation.js';
|
|
128
|
+
import { SubtreeFacts, type SyntaxFacts } from './syntax-facts.js';
|
|
129
|
+
import { Transformer } from './transformer.js';
|
|
130
|
+
import { hasDecorators, singleOrMany, OuterExpressionKinds, skipOuterExpressions } from './utilities.js';
|
|
131
|
+
import { VisitorBase } from './visitor-base.js';
|
|
132
|
+
|
|
133
|
+
const enum LexicalEntryKind {
|
|
134
|
+
Class,
|
|
135
|
+
ClassElement,
|
|
136
|
+
Name,
|
|
137
|
+
Other,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** An entry of the stack of classes, class elements, names and other scopes being visited. */
|
|
141
|
+
class LexicalEntry {
|
|
142
|
+
readonly kind: LexicalEntryKind;
|
|
143
|
+
readonly next: LexicalEntry | undefined;
|
|
144
|
+
readonly classInfo: ClassInfo | undefined;
|
|
145
|
+
readonly savedPendingExpressions: Node[] | undefined;
|
|
146
|
+
classThis: Identifier | undefined;
|
|
147
|
+
classSuper: Identifier | undefined;
|
|
148
|
+
depth: number;
|
|
149
|
+
|
|
150
|
+
constructor(
|
|
151
|
+
kind: LexicalEntryKind,
|
|
152
|
+
next: LexicalEntry | undefined,
|
|
153
|
+
classInfo: ClassInfo | undefined,
|
|
154
|
+
savedPendingExpressions: Node[] | undefined,
|
|
155
|
+
) {
|
|
156
|
+
this.kind = kind;
|
|
157
|
+
this.next = next;
|
|
158
|
+
this.classInfo = classInfo;
|
|
159
|
+
this.savedPendingExpressions = savedPendingExpressions;
|
|
160
|
+
this.classThis = undefined;
|
|
161
|
+
this.classSuper = undefined;
|
|
162
|
+
this.depth = 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The helper variables of one decorated class element. */
|
|
167
|
+
class MemberInfo {
|
|
168
|
+
readonly decoratorsName: Identifier;
|
|
169
|
+
initializersName: Identifier | undefined;
|
|
170
|
+
extraInitializersName: Identifier | undefined;
|
|
171
|
+
descriptorName: Identifier | undefined;
|
|
172
|
+
|
|
173
|
+
constructor(decoratorsName: Identifier) {
|
|
174
|
+
this.decoratorsName = decoratorsName;
|
|
175
|
+
this.initializersName = undefined;
|
|
176
|
+
this.extraInitializersName = undefined;
|
|
177
|
+
this.descriptorName = undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** What transforming one decorated class collects. */
|
|
182
|
+
class ClassInfo {
|
|
183
|
+
readonly metadataReference: Identifier;
|
|
184
|
+
classDecoratorsName: Identifier | undefined;
|
|
185
|
+
classDescriptorName: Identifier | undefined;
|
|
186
|
+
classExtraInitializersName: Identifier | undefined;
|
|
187
|
+
classThis: Identifier | undefined;
|
|
188
|
+
classSuper: Identifier | undefined;
|
|
189
|
+
/** Decorated members, in order, and their helper variables. */
|
|
190
|
+
readonly decoratedMembers: Node[];
|
|
191
|
+
readonly memberInfos: MemberInfo[];
|
|
192
|
+
instanceMethodExtraInitializersName: Identifier | undefined;
|
|
193
|
+
staticMethodExtraInitializersName: Identifier | undefined;
|
|
194
|
+
readonly staticNonFieldDecorationStatements: Node[];
|
|
195
|
+
readonly nonStaticNonFieldDecorationStatements: Node[];
|
|
196
|
+
readonly staticFieldDecorationStatements: Node[];
|
|
197
|
+
readonly nonStaticFieldDecorationStatements: Node[];
|
|
198
|
+
hasStaticInitializers: boolean;
|
|
199
|
+
hasNonAmbientInstanceFields: boolean;
|
|
200
|
+
hasStaticPrivateClassElements: boolean;
|
|
201
|
+
pendingStaticInitializers: Node[];
|
|
202
|
+
pendingInstanceInitializers: Node[];
|
|
203
|
+
|
|
204
|
+
constructor(metadataReference: Identifier) {
|
|
205
|
+
this.metadataReference = metadataReference;
|
|
206
|
+
this.classDecoratorsName = undefined;
|
|
207
|
+
this.classDescriptorName = undefined;
|
|
208
|
+
this.classExtraInitializersName = undefined;
|
|
209
|
+
this.classThis = undefined;
|
|
210
|
+
this.classSuper = undefined;
|
|
211
|
+
this.decoratedMembers = [];
|
|
212
|
+
this.memberInfos = [];
|
|
213
|
+
this.instanceMethodExtraInitializersName = undefined;
|
|
214
|
+
this.staticMethodExtraInitializersName = undefined;
|
|
215
|
+
this.staticNonFieldDecorationStatements = [];
|
|
216
|
+
this.nonStaticNonFieldDecorationStatements = [];
|
|
217
|
+
this.staticFieldDecorationStatements = [];
|
|
218
|
+
this.nonStaticFieldDecorationStatements = [];
|
|
219
|
+
this.hasStaticInitializers = false;
|
|
220
|
+
this.hasNonAmbientInstanceFields = false;
|
|
221
|
+
this.hasStaticPrivateClassElements = false;
|
|
222
|
+
this.pendingStaticInitializers = [];
|
|
223
|
+
this.pendingInstanceInitializers = [];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
setMemberInfo(member: Node, info: MemberInfo): boolean {
|
|
227
|
+
const index = this.decoratedMembers.indexOf(member);
|
|
228
|
+
if (index >= 0) this.memberInfos[index] = info;
|
|
229
|
+
else {
|
|
230
|
+
this.decoratedMembers.push(member);
|
|
231
|
+
this.memberInfos.push(info);
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** The result of the shared part of transforming a class element. */
|
|
238
|
+
class PartialResult {
|
|
239
|
+
modifiers: ModifierList | undefined;
|
|
240
|
+
referencedName: Node | undefined;
|
|
241
|
+
name: Node | undefined;
|
|
242
|
+
initializersName: Identifier | undefined;
|
|
243
|
+
extraInitializersName: Identifier | undefined;
|
|
244
|
+
descriptorName: Identifier | undefined;
|
|
245
|
+
thisArg: Identifier | undefined;
|
|
246
|
+
|
|
247
|
+
constructor(modifiers: ModifierList | undefined) {
|
|
248
|
+
this.modifiers = modifiers;
|
|
249
|
+
this.referencedName = undefined;
|
|
250
|
+
this.name = undefined;
|
|
251
|
+
this.initializersName = undefined;
|
|
252
|
+
this.extraInitializersName = undefined;
|
|
253
|
+
this.descriptorName = undefined;
|
|
254
|
+
this.thisArg = undefined;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Which pseudo-descriptor a private decorated element's body moves into. */
|
|
259
|
+
const enum DescriptorKind {
|
|
260
|
+
None,
|
|
261
|
+
Method,
|
|
262
|
+
GetAccessor,
|
|
263
|
+
SetAccessor,
|
|
264
|
+
AccessorProperty,
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Which modifiers a modifier filter keeps. */
|
|
268
|
+
const enum ModifierFilter {
|
|
269
|
+
/** All but decorators. */
|
|
270
|
+
NoDecorators,
|
|
271
|
+
/** All but decorators and `export`. */
|
|
272
|
+
NoExport,
|
|
273
|
+
StaticOnly,
|
|
274
|
+
AsyncOnly,
|
|
275
|
+
/** All but `accessor`. */
|
|
276
|
+
NoAccessor,
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Which visitor a list of nodes is visited with. */
|
|
280
|
+
const enum ListVisit {
|
|
281
|
+
ClassElements,
|
|
282
|
+
NonConstructorClassElements,
|
|
283
|
+
ConstructorClassElements,
|
|
284
|
+
ArrayAssignmentElements,
|
|
285
|
+
ObjectAssignmentElements,
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** Anonymous decorated class expressions, which need an assigned name. */
|
|
289
|
+
class AnonymousDecoratedClassFilter extends AnonymousFunctionFilter {
|
|
290
|
+
accepts(node: Node): boolean {
|
|
291
|
+
return node instanceof ClassExpression && node.name === undefined && isDecoratedClassLike(node);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const anonymousDecoratedClass = new AnonymousDecoratedClassFilter();
|
|
296
|
+
|
|
297
|
+
function isDecoratedClassLike(node: Node): boolean {
|
|
298
|
+
return classOrConstructorParameterIsDecorated(false, node) || childIsDecorated(false, node, undefined);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* The IIFE for `(@dec class {})` assigns `var class_1 = class {}`, so an empty assigned name
|
|
303
|
+
* matters; the one for `(class { @dec x; })` returns the class directly, so it can be ignored.
|
|
304
|
+
*/
|
|
305
|
+
function canIgnoreEmptyStringLiteralInAssignedName(node: Node | undefined): boolean {
|
|
306
|
+
if (node === undefined) return false;
|
|
307
|
+
const inner = skipOuterExpressions(node, OuterExpressionKinds.All);
|
|
308
|
+
return (
|
|
309
|
+
inner instanceof ClassExpression &&
|
|
310
|
+
inner.name === undefined &&
|
|
311
|
+
!classOrConstructorParameterIsDecorated(false, inner)
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Replaces lexical `this` with `_outerThis`, for expressions moved into a class `static {}` block. */
|
|
316
|
+
class OuterThisVisitor extends VisitorBase {
|
|
317
|
+
private readonly owner: ESDecorators;
|
|
318
|
+
|
|
319
|
+
constructor(owner: ESDecorators) {
|
|
320
|
+
super(owner.context);
|
|
321
|
+
this.owner = owner;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
visit(node: Node): Node | undefined {
|
|
325
|
+
return this.owner.visitOuterThis(node, this);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Whether ES decorators need lowering for these options. */
|
|
330
|
+
export function shouldTransformESDecorators(options: CompilerOptions): boolean {
|
|
331
|
+
if (options.experimentalDecorators === true) return false;
|
|
332
|
+
return getEmitScriptTarget(options) < ScriptTarget.ESNext || !getUseDefineForClassFields(options);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export class ESDecorators extends Transformer {
|
|
336
|
+
private readonly facts: SyntaxFacts;
|
|
337
|
+
private readonly outerThisVisitor: OuterThisVisitor;
|
|
338
|
+
private top: LexicalEntry | undefined;
|
|
339
|
+
private classInfo: ClassInfo | undefined;
|
|
340
|
+
private classThis: Identifier | undefined;
|
|
341
|
+
private classSuper: Identifier | undefined;
|
|
342
|
+
private pendingExpressions: Node[];
|
|
343
|
+
private outerThis: Identifier | undefined;
|
|
344
|
+
private shouldTransformPrivateStaticElementsInFile: boolean;
|
|
345
|
+
|
|
346
|
+
constructor(context: EmitContext, facts: SyntaxFacts) {
|
|
347
|
+
super(context);
|
|
348
|
+
this.facts = facts;
|
|
349
|
+
this.outerThisVisitor = new OuterThisVisitor(this);
|
|
350
|
+
this.top = undefined;
|
|
351
|
+
this.classInfo = undefined;
|
|
352
|
+
this.classThis = undefined;
|
|
353
|
+
this.classSuper = undefined;
|
|
354
|
+
this.pendingExpressions = [];
|
|
355
|
+
this.outerThis = undefined;
|
|
356
|
+
this.shouldTransformPrivateStaticElementsInFile = false;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
// Lexical state
|
|
360
|
+
|
|
361
|
+
private updateState(): boolean {
|
|
362
|
+
this.classInfo = undefined;
|
|
363
|
+
this.classThis = undefined;
|
|
364
|
+
this.classSuper = undefined;
|
|
365
|
+
const top = this.top;
|
|
366
|
+
if (top === undefined) return false;
|
|
367
|
+
switch (top.kind) {
|
|
368
|
+
case LexicalEntryKind.Class:
|
|
369
|
+
this.classInfo = top.classInfo;
|
|
370
|
+
break;
|
|
371
|
+
case LexicalEntryKind.ClassElement:
|
|
372
|
+
this.classInfo = top.next!.classInfo;
|
|
373
|
+
this.classThis = top.classThis;
|
|
374
|
+
this.classSuper = top.classSuper;
|
|
375
|
+
break;
|
|
376
|
+
case LexicalEntryKind.Name: {
|
|
377
|
+
const grandparent = top.next!.next!.next;
|
|
378
|
+
if (grandparent !== undefined && grandparent.kind === LexicalEntryKind.ClassElement) {
|
|
379
|
+
this.classInfo = grandparent.next!.classInfo;
|
|
380
|
+
this.classThis = grandparent.classThis;
|
|
381
|
+
this.classSuper = grandparent.classSuper;
|
|
382
|
+
}
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return true;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
private enterClass(info: ClassInfo | undefined): boolean {
|
|
390
|
+
this.top = new LexicalEntry(LexicalEntryKind.Class, this.top, info, this.pendingExpressions);
|
|
391
|
+
this.pendingExpressions = [];
|
|
392
|
+
return this.updateState();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
private exitClass(): boolean {
|
|
396
|
+
const top = this.top!;
|
|
397
|
+
this.pendingExpressions = top.savedPendingExpressions!;
|
|
398
|
+
this.top = top.next;
|
|
399
|
+
return this.updateState();
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private enterClassElement(node: Node): boolean {
|
|
403
|
+
const entry = new LexicalEntry(LexicalEntryKind.ClassElement, this.top, undefined, undefined);
|
|
404
|
+
this.top = entry;
|
|
405
|
+
if (
|
|
406
|
+
node.kind === SyntaxKind.ClassStaticBlockDeclaration ||
|
|
407
|
+
(node.kind === SyntaxKind.PropertyDeclaration && hasStaticModifier(node))
|
|
408
|
+
) {
|
|
409
|
+
const info = entry.next!.classInfo;
|
|
410
|
+
if (info !== undefined) {
|
|
411
|
+
entry.classThis = info.classThis;
|
|
412
|
+
entry.classSuper = info.classSuper;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return this.updateState();
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private exitClassElement(): boolean {
|
|
419
|
+
this.top = this.top!.next;
|
|
420
|
+
return this.updateState();
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private enterName(): boolean {
|
|
424
|
+
this.top = new LexicalEntry(LexicalEntryKind.Name, this.top, undefined, undefined);
|
|
425
|
+
return this.updateState();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private exitName(): boolean {
|
|
429
|
+
this.top = this.top!.next;
|
|
430
|
+
return this.updateState();
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
private enterOther(): boolean {
|
|
434
|
+
const top = this.top;
|
|
435
|
+
if (top !== undefined && top.kind === LexicalEntryKind.Other) {
|
|
436
|
+
top.depth++;
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
this.top = new LexicalEntry(LexicalEntryKind.Other, top, undefined, this.pendingExpressions);
|
|
440
|
+
this.pendingExpressions = [];
|
|
441
|
+
return this.updateState();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private exitOther(): boolean {
|
|
445
|
+
const top = this.top!;
|
|
446
|
+
if (top.depth > 0) {
|
|
447
|
+
top.depth--;
|
|
448
|
+
return true;
|
|
449
|
+
}
|
|
450
|
+
this.pendingExpressions = top.savedPendingExpressions!;
|
|
451
|
+
this.top = top.next;
|
|
452
|
+
return this.updateState();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Visitors
|
|
456
|
+
|
|
457
|
+
private shouldVisitNode(node: Node): boolean {
|
|
458
|
+
const facts = this.facts.of(node);
|
|
459
|
+
return (
|
|
460
|
+
(facts & SubtreeFacts.ContainsDecorators) !== 0 ||
|
|
461
|
+
(this.classThis !== undefined && (facts & SubtreeFacts.ContainsLexicalThis) !== 0) ||
|
|
462
|
+
(this.classThis !== undefined &&
|
|
463
|
+
this.classSuper !== undefined &&
|
|
464
|
+
(facts & SubtreeFacts.ContainsLexicalSuper) !== 0)
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
visit(node: Node): Node | undefined {
|
|
469
|
+
if (node instanceof SourceFile) return this.visitSourceFile(node as SourceFile);
|
|
470
|
+
if (!this.shouldVisitNode(node)) return node;
|
|
471
|
+
switch (node.kind) {
|
|
472
|
+
case SyntaxKind.Decorator:
|
|
473
|
+
return undefined;
|
|
474
|
+
case SyntaxKind.ClassDeclaration:
|
|
475
|
+
if (node instanceof ClassDeclaration) return this.visitClassDeclaration(node);
|
|
476
|
+
break;
|
|
477
|
+
case SyntaxKind.ClassExpression:
|
|
478
|
+
if (node instanceof ClassExpression) return this.visitClassExpression(node);
|
|
479
|
+
break;
|
|
480
|
+
case SyntaxKind.Constructor:
|
|
481
|
+
case SyntaxKind.PropertyDeclaration:
|
|
482
|
+
case SyntaxKind.ClassStaticBlockDeclaration:
|
|
483
|
+
throw new Error('Class elements are visited with visitClassElement');
|
|
484
|
+
case SyntaxKind.Parameter:
|
|
485
|
+
if (node instanceof ParameterDeclaration) return this.visitParameterDeclaration(node);
|
|
486
|
+
break;
|
|
487
|
+
case SyntaxKind.BinaryExpression:
|
|
488
|
+
if (node instanceof BinaryExpression) return this.visitBinaryExpression(node, false);
|
|
489
|
+
break;
|
|
490
|
+
case SyntaxKind.PropertyAssignment:
|
|
491
|
+
if (node instanceof PropertyAssignment) return this.visitNamedEvaluationSite(node, node.initializer);
|
|
492
|
+
break;
|
|
493
|
+
case SyntaxKind.VariableDeclaration:
|
|
494
|
+
if (node instanceof VariableDeclaration) return this.visitNamedEvaluationSite(node, node.initializer);
|
|
495
|
+
break;
|
|
496
|
+
case SyntaxKind.BindingElement:
|
|
497
|
+
if (node instanceof BindingElement) return this.visitNamedEvaluationSite(node, node.initializer);
|
|
498
|
+
break;
|
|
499
|
+
case SyntaxKind.ExportAssignment:
|
|
500
|
+
if (node instanceof ExportAssignment) return this.visitNamedEvaluationSite(node, node.expression);
|
|
501
|
+
break;
|
|
502
|
+
case SyntaxKind.ThisKeyword:
|
|
503
|
+
return this.classThis !== undefined ? this.classThis : node;
|
|
504
|
+
case SyntaxKind.ForStatement:
|
|
505
|
+
if (node instanceof ForStatement) return this.visitForStatement(node);
|
|
506
|
+
break;
|
|
507
|
+
case SyntaxKind.ExpressionStatement:
|
|
508
|
+
if (node instanceof ExpressionStatement)
|
|
509
|
+
return this.factory.updateExpressionStatement(node, this.visitDiscardedNode(node.expression)!);
|
|
510
|
+
break;
|
|
511
|
+
case SyntaxKind.ParenthesizedExpression:
|
|
512
|
+
if (node instanceof ParenthesizedExpression) return this.visitParenthesizedExpression(node, false);
|
|
513
|
+
break;
|
|
514
|
+
case SyntaxKind.PartiallyEmittedExpression:
|
|
515
|
+
if (node instanceof PartiallyEmittedExpression) return this.visitPartiallyEmittedExpression(node, false);
|
|
516
|
+
break;
|
|
517
|
+
case SyntaxKind.CallExpression:
|
|
518
|
+
if (node instanceof CallExpression) return this.visitCallExpression(node);
|
|
519
|
+
break;
|
|
520
|
+
case SyntaxKind.TaggedTemplateExpression:
|
|
521
|
+
if (node instanceof TaggedTemplateExpression) return this.visitTaggedTemplateExpression(node);
|
|
522
|
+
break;
|
|
523
|
+
case SyntaxKind.PrefixUnaryExpression:
|
|
524
|
+
case SyntaxKind.PostfixUnaryExpression:
|
|
525
|
+
return this.visitPreOrPostfixUnaryExpression(node, false);
|
|
526
|
+
case SyntaxKind.PropertyAccessExpression:
|
|
527
|
+
if (node instanceof PropertyAccessExpression) return this.visitPropertyAccessExpression(node);
|
|
528
|
+
break;
|
|
529
|
+
case SyntaxKind.ElementAccessExpression:
|
|
530
|
+
if (node instanceof ElementAccessExpression) return this.visitElementAccessExpression(node);
|
|
531
|
+
break;
|
|
532
|
+
case SyntaxKind.ComputedPropertyName:
|
|
533
|
+
if (node instanceof ComputedPropertyName) return this.visitComputedPropertyName(node);
|
|
534
|
+
break;
|
|
535
|
+
case SyntaxKind.MethodDeclaration:
|
|
536
|
+
case SyntaxKind.SetAccessor:
|
|
537
|
+
case SyntaxKind.GetAccessor:
|
|
538
|
+
case SyntaxKind.FunctionExpression:
|
|
539
|
+
case SyntaxKind.FunctionDeclaration: {
|
|
540
|
+
this.enterOther();
|
|
541
|
+
const result = this.visitEachChild(node);
|
|
542
|
+
this.exitOther();
|
|
543
|
+
return result;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return this.visitEachChild(node);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
private visitSourceFile(node: SourceFile): Node {
|
|
550
|
+
this.top = undefined;
|
|
551
|
+
this.shouldTransformPrivateStaticElementsInFile = false;
|
|
552
|
+
const visited = this.visitEachChild(node);
|
|
553
|
+
const helpers = this.context.readEmitHelpers();
|
|
554
|
+
for (let i = 0; i < helpers.length; i++) this.context.addEmitHelper(visited, helpers[i]);
|
|
555
|
+
if (this.shouldTransformPrivateStaticElementsInFile) {
|
|
556
|
+
this.context.addEmitFlags(visited, EmitFlags.TransformPrivateStaticElements);
|
|
557
|
+
this.shouldTransformPrivateStaticElementsInFile = false;
|
|
558
|
+
}
|
|
559
|
+
return visited;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/** `this` as `_outerThis`, for the outer-this visitor. */
|
|
563
|
+
visitOuterThis(node: Node, visitor: OuterThisVisitor): Node | undefined {
|
|
564
|
+
if (node.kind === SyntaxKind.ThisKeyword) {
|
|
565
|
+
if (this.outerThis === undefined)
|
|
566
|
+
this.outerThis = this.factory.createUniqueName('_outerThis', GeneratedIdentifierFlags.Optimistic);
|
|
567
|
+
return this.outerThis;
|
|
568
|
+
}
|
|
569
|
+
if (!this.facts.has(node, SubtreeFacts.ContainsLexicalThis)) return node;
|
|
570
|
+
return visitor.visitEachChild(node);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
private visitClassElement(node: Node): Node | undefined {
|
|
574
|
+
switch (node.kind) {
|
|
575
|
+
case SyntaxKind.Constructor:
|
|
576
|
+
if (node instanceof ConstructorDeclaration) return this.visitConstructorDeclaration(node);
|
|
577
|
+
break;
|
|
578
|
+
case SyntaxKind.MethodDeclaration:
|
|
579
|
+
if (node instanceof MethodDeclaration) return this.visitMethodDeclaration(node);
|
|
580
|
+
break;
|
|
581
|
+
case SyntaxKind.GetAccessor:
|
|
582
|
+
if (node instanceof GetAccessorDeclaration) return this.visitGetAccessorDeclaration(node);
|
|
583
|
+
break;
|
|
584
|
+
case SyntaxKind.SetAccessor:
|
|
585
|
+
if (node instanceof SetAccessorDeclaration) return this.visitSetAccessorDeclaration(node);
|
|
586
|
+
break;
|
|
587
|
+
case SyntaxKind.PropertyDeclaration:
|
|
588
|
+
if (node instanceof PropertyDeclaration) return this.visitPropertyDeclaration(node);
|
|
589
|
+
break;
|
|
590
|
+
case SyntaxKind.ClassStaticBlockDeclaration:
|
|
591
|
+
if (node instanceof ClassStaticBlockDeclaration) return this.visitClassStaticBlockDeclaration(node);
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
return this.visit(node);
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** Visits a node whose value is discarded, such as an expression statement's expression. */
|
|
598
|
+
private visitDiscarded(node: Node): Node | undefined {
|
|
599
|
+
switch (node.kind) {
|
|
600
|
+
case SyntaxKind.PrefixUnaryExpression:
|
|
601
|
+
case SyntaxKind.PostfixUnaryExpression:
|
|
602
|
+
return this.visitPreOrPostfixUnaryExpression(node, true);
|
|
603
|
+
case SyntaxKind.BinaryExpression:
|
|
604
|
+
if (node instanceof BinaryExpression) return this.visitBinaryExpression(node, true);
|
|
605
|
+
break;
|
|
606
|
+
case SyntaxKind.ParenthesizedExpression:
|
|
607
|
+
if (node instanceof ParenthesizedExpression) return this.visitParenthesizedExpression(node, true);
|
|
608
|
+
break;
|
|
609
|
+
case SyntaxKind.PartiallyEmittedExpression:
|
|
610
|
+
if (node instanceof PartiallyEmittedExpression) return this.visitPartiallyEmittedExpression(node, true);
|
|
611
|
+
break;
|
|
612
|
+
}
|
|
613
|
+
return this.visit(node);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
private visitDiscardedNode(node: Node | undefined): Node | undefined {
|
|
617
|
+
return node === undefined ? undefined : this.visitDiscarded(node);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
private visitListItem(node: Node, mode: ListVisit): Node | undefined {
|
|
621
|
+
switch (mode) {
|
|
622
|
+
case ListVisit.ClassElements:
|
|
623
|
+
return this.visitClassElement(node);
|
|
624
|
+
case ListVisit.NonConstructorClassElements:
|
|
625
|
+
return node.kind === SyntaxKind.Constructor ? node : this.visitClassElement(node);
|
|
626
|
+
case ListVisit.ConstructorClassElements:
|
|
627
|
+
return node.kind === SyntaxKind.Constructor ? this.visitClassElement(node) : node;
|
|
628
|
+
case ListVisit.ArrayAssignmentElements:
|
|
629
|
+
return this.visitArrayAssignmentElement(node);
|
|
630
|
+
case ListVisit.ObjectAssignmentElements:
|
|
631
|
+
return this.visitObjectAssignmentElement(node);
|
|
632
|
+
}
|
|
633
|
+
return node;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/** Visits each node of a list with the visitor `mode` names; the list itself if nothing changed. */
|
|
637
|
+
private visitList(list: NodeList, mode: ListVisit): NodeList {
|
|
638
|
+
const nodes = list.nodes;
|
|
639
|
+
let updated: Node[] | undefined = undefined;
|
|
640
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
641
|
+
const visited = this.visitListItem(nodes[i], mode);
|
|
642
|
+
if (updated === undefined) {
|
|
643
|
+
if (visited === nodes[i]) continue;
|
|
644
|
+
updated = nodes.slice(0, i);
|
|
645
|
+
}
|
|
646
|
+
if (visited instanceof SyntaxList)
|
|
647
|
+
for (let j = 0; j < visited.children.length; j++) updated.push(visited.children[j]);
|
|
648
|
+
else if (visited !== undefined) updated.push(visited);
|
|
649
|
+
}
|
|
650
|
+
return updated === undefined ? list : new NodeList(list.pos, list.end, updated);
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
private filterModifiers(list: ModifierList | undefined, filter: ModifierFilter): ModifierList | undefined {
|
|
654
|
+
if (list === undefined) return undefined;
|
|
655
|
+
const nodes = list.nodes;
|
|
656
|
+
let kept: Node[] | undefined = undefined;
|
|
657
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
658
|
+
const keep = keepsModifier(filter, nodes[i].kind);
|
|
659
|
+
if (keep && kept !== undefined) kept.push(nodes[i]);
|
|
660
|
+
else if (!keep && kept === undefined) kept = nodes.slice(0, i);
|
|
661
|
+
}
|
|
662
|
+
if (kept === undefined) return list;
|
|
663
|
+
const updated = this.factory.createModifierList(kept);
|
|
664
|
+
updated.pos = list.pos;
|
|
665
|
+
updated.end = list.end;
|
|
666
|
+
return updated;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
// Classes
|
|
670
|
+
|
|
671
|
+
private createHelperVariable(node: Node, suffix: string): Identifier {
|
|
672
|
+
return this.factory.createUniqueName(
|
|
673
|
+
getHelperVariableName(this.context, node) + '_' + suffix,
|
|
674
|
+
GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.ReservedInNestedScopes,
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
private createFileLevelName(text: string): Identifier {
|
|
679
|
+
return this.factory.createUniqueName(
|
|
680
|
+
text,
|
|
681
|
+
GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel,
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
private createLet(name: Identifier, initializer: Node | undefined): VariableStatement {
|
|
686
|
+
const factory = this.factory;
|
|
687
|
+
return factory.createVariableStatement(
|
|
688
|
+
undefined,
|
|
689
|
+
factory.createVariableDeclarationList(
|
|
690
|
+
factory.createNodeList([factory.createVariableDeclaration(name, undefined, undefined, initializer)]),
|
|
691
|
+
NodeFlags.Let,
|
|
692
|
+
),
|
|
693
|
+
);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
private createEmptyArray(): ArrayLiteralExpression {
|
|
697
|
+
return this.factory.created(new ArrayLiteralExpression(this.factory.createNodeList([]), false));
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
private setRangePastDecoratorsOrName(initializer: Node, node: Node): boolean {
|
|
701
|
+
const name = getClassName(node);
|
|
702
|
+
if (name !== undefined) this.context.setSourceMapRange(initializer, name.pos, name.end);
|
|
703
|
+
else this.context.setSourceMapRange(initializer, moveRangePastDecorators(node).pos, node.end);
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
private createClassInfo(node: Node): ClassInfo {
|
|
708
|
+
const factory = this.factory;
|
|
709
|
+
const info = new ClassInfo(this.createFileLevelName('_metadata'));
|
|
710
|
+
const members = getClassMembers(node).nodes;
|
|
711
|
+
if (nodeIsDecorated(false, node, undefined, undefined)) {
|
|
712
|
+
let needsUniqueClassThis = false;
|
|
713
|
+
for (let i = 0; i < members.length; i++)
|
|
714
|
+
if (isStaticPrivateOrAutoAccessor(members[i])) {
|
|
715
|
+
needsUniqueClassThis = true;
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
// `_classThis` isn't file level when class private fields may need an outer class's.
|
|
719
|
+
info.classThis = factory.createUniqueName(
|
|
720
|
+
'_classThis',
|
|
721
|
+
needsUniqueClassThis
|
|
722
|
+
? GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.ReservedInNestedScopes
|
|
723
|
+
: GeneratedIdentifierFlags.Optimistic | GeneratedIdentifierFlags.FileLevel,
|
|
724
|
+
);
|
|
725
|
+
}
|
|
726
|
+
for (let i = 0; i < members.length; i++) {
|
|
727
|
+
const member = members[i];
|
|
728
|
+
if (isMethodOrAccessor(member) && nodeOrChildIsDecorated(false, member, node, undefined)) {
|
|
729
|
+
if (hasStaticModifier(member)) {
|
|
730
|
+
if (info.staticMethodExtraInitializersName === undefined) {
|
|
731
|
+
info.staticMethodExtraInitializersName = this.createFileLevelName('_staticExtraInitializers');
|
|
732
|
+
const initializer = createRunInitializersHelper(
|
|
733
|
+
factory,
|
|
734
|
+
info.classThis !== undefined ? info.classThis : factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
735
|
+
info.staticMethodExtraInitializersName,
|
|
736
|
+
undefined,
|
|
737
|
+
);
|
|
738
|
+
this.setRangePastDecoratorsOrName(initializer, node);
|
|
739
|
+
info.pendingStaticInitializers.push(initializer);
|
|
740
|
+
}
|
|
741
|
+
} else if (info.instanceMethodExtraInitializersName === undefined) {
|
|
742
|
+
info.instanceMethodExtraInitializersName = this.createFileLevelName('_instanceExtraInitializers');
|
|
743
|
+
const initializer = createRunInitializersHelper(
|
|
744
|
+
factory,
|
|
745
|
+
factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
746
|
+
info.instanceMethodExtraInitializersName,
|
|
747
|
+
undefined,
|
|
748
|
+
);
|
|
749
|
+
this.setRangePastDecoratorsOrName(initializer, node);
|
|
750
|
+
info.pendingInstanceInitializers.push(initializer);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
if (member instanceof ClassStaticBlockDeclaration) {
|
|
754
|
+
if (!isClassNamedEvaluationHelperBlock(this.context, member)) info.hasStaticInitializers = true;
|
|
755
|
+
} else if (member instanceof PropertyDeclaration) {
|
|
756
|
+
if (hasStaticModifier(member))
|
|
757
|
+
info.hasStaticInitializers =
|
|
758
|
+
info.hasStaticInitializers || member.initializer !== undefined || hasDecorators(member);
|
|
759
|
+
else
|
|
760
|
+
info.hasNonAmbientInstanceFields =
|
|
761
|
+
info.hasNonAmbientInstanceFields || !hasSyntacticModifier(member, ModifierFlags.Ambient);
|
|
762
|
+
}
|
|
763
|
+
if (isStaticPrivateOrAutoAccessor(member)) info.hasStaticPrivateClassElements = true;
|
|
764
|
+
if (
|
|
765
|
+
info.staticMethodExtraInitializersName !== undefined &&
|
|
766
|
+
info.instanceMethodExtraInitializersName !== undefined &&
|
|
767
|
+
info.hasStaticInitializers &&
|
|
768
|
+
info.hasNonAmbientInstanceFields &&
|
|
769
|
+
info.hasStaticPrivateClassElements
|
|
770
|
+
)
|
|
771
|
+
break;
|
|
772
|
+
}
|
|
773
|
+
return info;
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
private transformClassLike(original: Node): Node {
|
|
777
|
+
const factory = this.factory;
|
|
778
|
+
const context = this.context;
|
|
779
|
+
context.startVariableEnvironment();
|
|
780
|
+
let node: Node = original;
|
|
781
|
+
// A class that gets class decorators is moved into a statement that would give it an
|
|
782
|
+
// assigned name; without one, it gets the assigned name `""`.
|
|
783
|
+
if (!classHasDeclaredOrExplicitlyAssignedName(context, node) && classOrConstructorParameterIsDecorated(false, node))
|
|
784
|
+
node = injectClassNamedEvaluationHelperBlockIfMissing(
|
|
785
|
+
context,
|
|
786
|
+
node,
|
|
787
|
+
factory.createStringLiteral('', TokenFlags.None),
|
|
788
|
+
undefined,
|
|
789
|
+
);
|
|
790
|
+
const cls = node;
|
|
791
|
+
const classMembers = getClassMembers(cls);
|
|
792
|
+
const classReference = factory.getLocalName(cls, NameOptions.None);
|
|
793
|
+
const info = this.createClassInfo(cls);
|
|
794
|
+
const classDefinitionStatements: Node[] = [];
|
|
795
|
+
let leadingBlockStatements: Node[] = [];
|
|
796
|
+
let trailingBlockStatements: Node[] = [];
|
|
797
|
+
let syntheticConstructor: Node | undefined = undefined;
|
|
798
|
+
let heritageClauses: NodeList | undefined = undefined;
|
|
799
|
+
let shouldTransformPrivateStaticElementsInClass = false;
|
|
800
|
+
|
|
801
|
+
// 1. Class decorators are evaluated outside the private name scope of the class.
|
|
802
|
+
const classDecorators = this.transformAllDecoratorsOfDeclaration(getDecorators(cls));
|
|
803
|
+
if (classDecorators.length > 0) {
|
|
804
|
+
info.classDecoratorsName = this.createFileLevelName('_classDecorators');
|
|
805
|
+
info.classDescriptorName = this.createFileLevelName('_classDescriptor');
|
|
806
|
+
info.classExtraInitializersName = this.createFileLevelName('_classExtraInitializers');
|
|
807
|
+
classDefinitionStatements.push(
|
|
808
|
+
this.createLet(
|
|
809
|
+
info.classDecoratorsName,
|
|
810
|
+
factory.created(new ArrayLiteralExpression(factory.createNodeList(classDecorators), false)),
|
|
811
|
+
),
|
|
812
|
+
this.createLet(info.classDescriptorName, undefined),
|
|
813
|
+
this.createLet(info.classExtraInitializersName, this.createEmptyArray()),
|
|
814
|
+
this.createLet(info.classThis!, undefined),
|
|
815
|
+
);
|
|
816
|
+
if (info.hasStaticPrivateClassElements) {
|
|
817
|
+
shouldTransformPrivateStaticElementsInClass = true;
|
|
818
|
+
this.shouldTransformPrivateStaticElementsInFile = true;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// 2. The heritage clause is evaluated outside the private name scope of the class.
|
|
823
|
+
const extendsClause = getHeritageClause(getClassHeritageClauses(cls), SyntaxKind.ExtendsKeyword);
|
|
824
|
+
let extendsElement: ExpressionWithTypeArguments | undefined = undefined;
|
|
825
|
+
if (extendsClause !== undefined && extendsClause.types.nodes.length > 0) {
|
|
826
|
+
const first = extendsClause.types.nodes[0];
|
|
827
|
+
if (first instanceof ExpressionWithTypeArguments) extendsElement = first as ExpressionWithTypeArguments;
|
|
828
|
+
}
|
|
829
|
+
const extendsExpression = extendsElement !== undefined ? this.visitNode(extendsElement.expression) : undefined;
|
|
830
|
+
const heritageElement = extendsElement;
|
|
831
|
+
if (extendsClause !== undefined && heritageElement !== undefined && extendsExpression !== undefined) {
|
|
832
|
+
// `super` in static initializers is rewritten to use `_classSuper` with the right `this`.
|
|
833
|
+
info.classSuper = this.createFileLevelName('_classSuper');
|
|
834
|
+
// `0, ` keeps the variable from assigning a name to an anonymous class or function.
|
|
835
|
+
const unwrapped = skipOuterExpressions(extendsExpression, OuterExpressionKinds.All);
|
|
836
|
+
const anonymous =
|
|
837
|
+
(unwrapped instanceof ClassExpression && unwrapped.name === undefined) ||
|
|
838
|
+
(unwrapped instanceof FunctionExpression && unwrapped.name === undefined) ||
|
|
839
|
+
unwrapped.kind === SyntaxKind.ArrowFunction;
|
|
840
|
+
const safeExtendsExpression = anonymous
|
|
841
|
+
? factory.createCommaExpression(factory.createNumericLiteral('0'), extendsExpression)
|
|
842
|
+
: extendsExpression;
|
|
843
|
+
classDefinitionStatements.push(this.createLet(info.classSuper, safeExtendsExpression));
|
|
844
|
+
const updatedElement: Node = factory.updateExpressionWithTypeArguments(
|
|
845
|
+
heritageElement,
|
|
846
|
+
info.classSuper,
|
|
847
|
+
undefined,
|
|
848
|
+
);
|
|
849
|
+
const updatedClause: Node = factory.updateHeritageClause(
|
|
850
|
+
extendsClause,
|
|
851
|
+
extendsClause.token,
|
|
852
|
+
factory.createNodeList([updatedElement]),
|
|
853
|
+
);
|
|
854
|
+
heritageClauses = factory.createNodeList([updatedClause]);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
const renamedClassThis: Node =
|
|
858
|
+
info.classThis !== undefined ? info.classThis : factory.createKeywordExpression(SyntaxKind.ThisKeyword);
|
|
859
|
+
|
|
860
|
+
// 3. The name of the class is assigned (by the named evaluation block, if needed).
|
|
861
|
+
// 4. For each member, its decorators and then its computed name are evaluated. Members
|
|
862
|
+
// other than the constructor are visited first, since its transform depends on them.
|
|
863
|
+
this.enterClass(info);
|
|
864
|
+
leadingBlockStatements.push(this.createMetadata(info.metadataReference, info.classSuper));
|
|
865
|
+
let members = this.visitList(classMembers, ListVisit.NonConstructorClassElements);
|
|
866
|
+
members = this.visitList(members, ListVisit.ConstructorClassElements);
|
|
867
|
+
if (this.pendingExpressions.length > 0) {
|
|
868
|
+
// Lexical `this` in a pending expression is the container's, captured in `_outerThis`.
|
|
869
|
+
this.outerThis = undefined;
|
|
870
|
+
for (let i = 0; i < this.pendingExpressions.length; i++) {
|
|
871
|
+
let expression = this.pendingExpressions[i];
|
|
872
|
+
if (this.facts.has(expression, SubtreeFacts.ContainsLexicalThis))
|
|
873
|
+
expression = this.outerThisVisitor.visitNode(expression)!;
|
|
874
|
+
leadingBlockStatements.push(factory.createExpressionStatement(expression));
|
|
875
|
+
}
|
|
876
|
+
if (this.outerThis !== undefined)
|
|
877
|
+
classDefinitionStatements.unshift(
|
|
878
|
+
this.createLet(this.outerThis, factory.createKeywordExpression(SyntaxKind.ThisKeyword)),
|
|
879
|
+
);
|
|
880
|
+
this.pendingExpressions = [];
|
|
881
|
+
}
|
|
882
|
+
this.exitClass();
|
|
883
|
+
|
|
884
|
+
if (info.pendingInstanceInitializers.length > 0 && getFirstConstructorWithBody(cls) === undefined) {
|
|
885
|
+
const initializerStatements = this.prepareConstructor(info);
|
|
886
|
+
if (initializerStatements.length > 0) {
|
|
887
|
+
const heritage = extendsElement;
|
|
888
|
+
const isDerivedClass =
|
|
889
|
+
heritage !== undefined &&
|
|
890
|
+
skipOuterExpressions(heritage.expression, OuterExpressionKinds.All).kind !== SyntaxKind.NullKeyword;
|
|
891
|
+
const constructorStatements: Node[] = [];
|
|
892
|
+
if (isDerivedClass)
|
|
893
|
+
constructorStatements.push(
|
|
894
|
+
factory.createExpressionStatement(
|
|
895
|
+
factory.createCallExpression(factory.createKeywordExpression(SyntaxKind.SuperKeyword), [
|
|
896
|
+
factory.created(new SpreadElement(factory.createIdentifier('arguments'))),
|
|
897
|
+
]),
|
|
898
|
+
),
|
|
899
|
+
);
|
|
900
|
+
for (let i = 0; i < initializerStatements.length; i++) constructorStatements.push(initializerStatements[i]);
|
|
901
|
+
syntheticConstructor = factory.created(
|
|
902
|
+
new ConstructorDeclaration(
|
|
903
|
+
undefined,
|
|
904
|
+
undefined,
|
|
905
|
+
factory.createNodeList([]),
|
|
906
|
+
undefined,
|
|
907
|
+
undefined,
|
|
908
|
+
factory.createBlock(constructorStatements, true),
|
|
909
|
+
),
|
|
910
|
+
);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
if (info.staticMethodExtraInitializersName !== undefined)
|
|
915
|
+
classDefinitionStatements.push(this.createLet(info.staticMethodExtraInitializersName, this.createEmptyArray()));
|
|
916
|
+
if (info.instanceMethodExtraInitializersName !== undefined)
|
|
917
|
+
classDefinitionStatements.push(this.createLet(info.instanceMethodExtraInitializersName, this.createEmptyArray()));
|
|
918
|
+
if (info.memberInfos.length > 0) {
|
|
919
|
+
// Static members' variables come first.
|
|
920
|
+
this.addMemberInfoDeclarations(classDefinitionStatements, info, true);
|
|
921
|
+
this.addMemberInfoDeclarations(classDefinitionStatements, info, false);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
// 5-8. Member decorators are applied.
|
|
925
|
+
appendAll(leadingBlockStatements, info.staticNonFieldDecorationStatements);
|
|
926
|
+
appendAll(leadingBlockStatements, info.nonStaticNonFieldDecorationStatements);
|
|
927
|
+
appendAll(leadingBlockStatements, info.staticFieldDecorationStatements);
|
|
928
|
+
appendAll(leadingBlockStatements, info.nonStaticFieldDecorationStatements);
|
|
929
|
+
|
|
930
|
+
// 9. Class decorators are applied, and 10. the class binding is initialized:
|
|
931
|
+
// __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata }, null, _classExtraInitializers);
|
|
932
|
+
// C = _classThis = _classDescriptor.value;
|
|
933
|
+
if (
|
|
934
|
+
info.classDescriptorName !== undefined &&
|
|
935
|
+
info.classDecoratorsName !== undefined &&
|
|
936
|
+
info.classExtraInitializersName !== undefined &&
|
|
937
|
+
info.classThis !== undefined
|
|
938
|
+
) {
|
|
939
|
+
const classDescriptor = factory.createObjectLiteral(
|
|
940
|
+
[factory.createPropertyAssignment(factory.createIdentifier('value'), renamedClassThis)],
|
|
941
|
+
false,
|
|
942
|
+
);
|
|
943
|
+
const contextObject = factory.createObjectLiteral(
|
|
944
|
+
[
|
|
945
|
+
factory.createPropertyAssignment(
|
|
946
|
+
factory.createIdentifier('kind'),
|
|
947
|
+
factory.createStringLiteral('class', TokenFlags.None),
|
|
948
|
+
),
|
|
949
|
+
factory.createPropertyAssignment(
|
|
950
|
+
factory.createIdentifier('name'),
|
|
951
|
+
factory.createPropertyAccessExpression(renamedClassThis, factory.createIdentifier('name')),
|
|
952
|
+
),
|
|
953
|
+
factory.createPropertyAssignment(factory.createIdentifier('metadata'), info.metadataReference),
|
|
954
|
+
],
|
|
955
|
+
false,
|
|
956
|
+
);
|
|
957
|
+
const decorate = factory.createExpressionStatement(
|
|
958
|
+
createESDecorateHelper(
|
|
959
|
+
factory,
|
|
960
|
+
factory.createToken(SyntaxKind.NullKeyword),
|
|
961
|
+
factory.createAssignment(info.classDescriptorName, classDescriptor),
|
|
962
|
+
info.classDecoratorsName,
|
|
963
|
+
contextObject,
|
|
964
|
+
factory.createToken(SyntaxKind.NullKeyword),
|
|
965
|
+
info.classExtraInitializersName,
|
|
966
|
+
),
|
|
967
|
+
);
|
|
968
|
+
context.setSourceMapRange(decorate, moveRangePastDecorators(cls).pos, cls.end);
|
|
969
|
+
leadingBlockStatements.push(decorate);
|
|
970
|
+
leadingBlockStatements.push(
|
|
971
|
+
factory.createExpressionStatement(
|
|
972
|
+
factory.createAssignment(
|
|
973
|
+
classReference,
|
|
974
|
+
factory.createAssignment(
|
|
975
|
+
info.classThis,
|
|
976
|
+
factory.createPropertyAccessExpression(info.classDescriptorName, factory.createIdentifier('value')),
|
|
977
|
+
),
|
|
978
|
+
),
|
|
979
|
+
),
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// if (_metadata) Object.defineProperty(C, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
984
|
+
leadingBlockStatements.push(this.createSymbolMetadata(renamedClassThis, info.metadataReference));
|
|
985
|
+
|
|
986
|
+
// 11. Static extra initializers and 12. static fields are run.
|
|
987
|
+
for (let i = 0; i < info.pendingStaticInitializers.length; i++) {
|
|
988
|
+
const initializer = info.pendingStaticInitializers[i];
|
|
989
|
+
const statement = factory.createExpressionStatement(initializer);
|
|
990
|
+
context.setSourceMapRange(statement, context.sourceMapPos(initializer), context.sourceMapEnd(initializer));
|
|
991
|
+
trailingBlockStatements.push(statement);
|
|
992
|
+
}
|
|
993
|
+
info.pendingStaticInitializers = [];
|
|
994
|
+
|
|
995
|
+
// 13. Class extra initializers are run.
|
|
996
|
+
if (info.classExtraInitializersName !== undefined) {
|
|
997
|
+
const statement = factory.createExpressionStatement(
|
|
998
|
+
createRunInitializersHelper(factory, renamedClassThis, info.classExtraInitializersName, undefined),
|
|
999
|
+
);
|
|
1000
|
+
this.setRangePastDecoratorsOrName(statement, cls);
|
|
1001
|
+
trailingBlockStatements.push(statement);
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// Without other static initializers, the leading and trailing blocks are one.
|
|
1005
|
+
if (leadingBlockStatements.length > 0 && trailingBlockStatements.length > 0 && !info.hasStaticInitializers) {
|
|
1006
|
+
appendAll(leadingBlockStatements, trailingBlockStatements);
|
|
1007
|
+
trailingBlockStatements = [];
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
let leadingStaticBlock: Node | undefined = undefined;
|
|
1011
|
+
if (leadingBlockStatements.length > 0)
|
|
1012
|
+
leadingStaticBlock = factory.created(
|
|
1013
|
+
new ClassStaticBlockDeclaration(undefined, factory.createBlock(leadingBlockStatements, true)),
|
|
1014
|
+
);
|
|
1015
|
+
// Tells the class fields transform not to rename `this` to `_classThis` in this block.
|
|
1016
|
+
if (leadingStaticBlock !== undefined && shouldTransformPrivateStaticElementsInClass)
|
|
1017
|
+
context.setEmitFlags(leadingStaticBlock, EmitFlags.TransformPrivateStaticElements);
|
|
1018
|
+
let trailingStaticBlock: Node | undefined = undefined;
|
|
1019
|
+
if (trailingBlockStatements.length > 0)
|
|
1020
|
+
trailingStaticBlock = factory.created(
|
|
1021
|
+
new ClassStaticBlockDeclaration(undefined, factory.createBlock(trailingBlockStatements, true)),
|
|
1022
|
+
);
|
|
1023
|
+
leadingBlockStatements = [];
|
|
1024
|
+
|
|
1025
|
+
if (leadingStaticBlock !== undefined || syntheticConstructor !== undefined || trailingStaticBlock !== undefined) {
|
|
1026
|
+
const existing = members.nodes;
|
|
1027
|
+
let helperBlockIndex = -1;
|
|
1028
|
+
for (let i = 0; i < existing.length; i++)
|
|
1029
|
+
if (isClassNamedEvaluationHelperBlock(context, existing[i])) {
|
|
1030
|
+
helperBlockIndex = i;
|
|
1031
|
+
break;
|
|
1032
|
+
}
|
|
1033
|
+
const updated: Node[] = [];
|
|
1034
|
+
if (leadingStaticBlock !== undefined) {
|
|
1035
|
+
// After the named evaluation block, if there is one.
|
|
1036
|
+
for (let i = 0; i <= helperBlockIndex; i++) updated.push(existing[i]);
|
|
1037
|
+
updated.push(leadingStaticBlock);
|
|
1038
|
+
for (let i = helperBlockIndex + 1; i < existing.length; i++) updated.push(existing[i]);
|
|
1039
|
+
} else appendAll(updated, existing);
|
|
1040
|
+
if (syntheticConstructor !== undefined) updated.push(syntheticConstructor);
|
|
1041
|
+
if (trailingStaticBlock !== undefined) updated.push(trailingStaticBlock);
|
|
1042
|
+
members = new NodeList(members.pos, members.end, updated);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
const lexicalEnvironment = context.endVariableEnvironment();
|
|
1046
|
+
let classExpression: Node;
|
|
1047
|
+
if (classDecorators.length > 0) {
|
|
1048
|
+
// `var` uses NamedEvaluation to name the class and is initialized before any `static {}` use:
|
|
1049
|
+
// (() => { let _classDecorators = [...]; ...; var C = class { static { ... } }; return C = _classThis; })();
|
|
1050
|
+
classExpression = factory.created(new ClassExpression(undefined, undefined, undefined, heritageClauses, members));
|
|
1051
|
+
context.setOriginal(classExpression, cls);
|
|
1052
|
+
if (info.classThis !== undefined)
|
|
1053
|
+
classExpression = injectClassThisAssignmentIfMissing(context, classExpression, info.classThis);
|
|
1054
|
+
classDefinitionStatements.push(
|
|
1055
|
+
factory.createVariableStatement(
|
|
1056
|
+
undefined,
|
|
1057
|
+
factory.createVariableDeclarationList(
|
|
1058
|
+
factory.createNodeList([
|
|
1059
|
+
factory.createVariableDeclaration(classReference, undefined, undefined, classExpression),
|
|
1060
|
+
]),
|
|
1061
|
+
NodeFlags.None,
|
|
1062
|
+
),
|
|
1063
|
+
),
|
|
1064
|
+
factory.createReturnStatement(
|
|
1065
|
+
info.classThis !== undefined ? factory.createAssignment(classReference, info.classThis) : classReference,
|
|
1066
|
+
),
|
|
1067
|
+
);
|
|
1068
|
+
} else {
|
|
1069
|
+
// return <classExpression>;
|
|
1070
|
+
classExpression = factory.created(
|
|
1071
|
+
new ClassExpression(undefined, getClassName(cls), undefined, heritageClauses, members),
|
|
1072
|
+
);
|
|
1073
|
+
context.setOriginal(classExpression, cls);
|
|
1074
|
+
classDefinitionStatements.push(factory.createReturnStatement(classExpression));
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
if (shouldTransformPrivateStaticElementsInClass && classExpression instanceof ClassExpression) {
|
|
1078
|
+
context.addEmitFlags(classExpression, EmitFlags.TransformPrivateStaticElements);
|
|
1079
|
+
const classMembers = classExpression.members.nodes;
|
|
1080
|
+
for (let i = 0; i < classMembers.length; i++)
|
|
1081
|
+
if (isStaticPrivateOrAutoAccessor(classMembers[i]))
|
|
1082
|
+
context.addEmitFlags(classMembers[i], EmitFlags.TransformPrivateStaticElements);
|
|
1083
|
+
}
|
|
1084
|
+
return factory.createImmediatelyInvokedArrowFunction(
|
|
1085
|
+
context.mergeEnvironment(classDefinitionStatements, lexicalEnvironment),
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
private addMemberInfoDeclarations(statements: Node[], info: ClassInfo, isStaticMember: boolean): boolean {
|
|
1090
|
+
for (let i = 0; i < info.memberInfos.length; i++) {
|
|
1091
|
+
if (isStatic(info.decoratedMembers[i]) !== isStaticMember) continue;
|
|
1092
|
+
const memberInfo = info.memberInfos[i];
|
|
1093
|
+
statements.push(this.createLet(memberInfo.decoratorsName, undefined));
|
|
1094
|
+
if (memberInfo.initializersName !== undefined)
|
|
1095
|
+
statements.push(this.createLet(memberInfo.initializersName, this.createEmptyArray()));
|
|
1096
|
+
if (memberInfo.extraInitializersName !== undefined)
|
|
1097
|
+
statements.push(this.createLet(memberInfo.extraInitializersName, this.createEmptyArray()));
|
|
1098
|
+
if (memberInfo.descriptorName !== undefined)
|
|
1099
|
+
statements.push(this.createLet(memberInfo.descriptorName, undefined));
|
|
1100
|
+
}
|
|
1101
|
+
return true;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
private visitClassDeclaration(node: ClassDeclaration): Node | undefined {
|
|
1105
|
+
const factory = this.factory;
|
|
1106
|
+
const context = this.context;
|
|
1107
|
+
if (!isDecoratedClassLike(node)) {
|
|
1108
|
+
const modifiers = this.filterModifiers(node.modifiers, ModifierFilter.NoDecorators);
|
|
1109
|
+
const heritageClauses = this.visitNodes(node.heritageClauses);
|
|
1110
|
+
this.enterClass(undefined);
|
|
1111
|
+
const members = this.visitList(node.members, ListVisit.ClassElements);
|
|
1112
|
+
this.exitClass();
|
|
1113
|
+
return factory.updateClassDeclaration(node, modifiers, node.name, undefined, heritageClauses, members);
|
|
1114
|
+
}
|
|
1115
|
+
const statements: Node[] = [];
|
|
1116
|
+
let originalClass = context.mostOriginal(node);
|
|
1117
|
+
if (!isClassLike(originalClass)) originalClass = node;
|
|
1118
|
+
const originalName = getName(originalClass);
|
|
1119
|
+
const className =
|
|
1120
|
+
originalName !== undefined
|
|
1121
|
+
? factory.createStringLiteralFromNode(originalName)
|
|
1122
|
+
: factory.createStringLiteral('default', TokenFlags.None);
|
|
1123
|
+
const isExport = hasSyntacticModifier(node, ModifierFlags.Export);
|
|
1124
|
+
const isDefault = hasSyntacticModifier(node, ModifierFlags.Default);
|
|
1125
|
+
let classNode: ClassDeclaration = node;
|
|
1126
|
+
if (node.name === undefined)
|
|
1127
|
+
classNode = injectClassNamedEvaluationHelperBlockIfMissing(
|
|
1128
|
+
context,
|
|
1129
|
+
node,
|
|
1130
|
+
className,
|
|
1131
|
+
undefined,
|
|
1132
|
+
) as ClassDeclaration;
|
|
1133
|
+
if (isExport && isDefault) {
|
|
1134
|
+
const iife = this.transformClassLike(classNode);
|
|
1135
|
+
if (classNode.name !== undefined) {
|
|
1136
|
+
// let C = (() => { ... })();
|
|
1137
|
+
// export default C;
|
|
1138
|
+
const declaration = factory.createVariableDeclaration(
|
|
1139
|
+
factory.getLocalName(classNode, NameOptions.None),
|
|
1140
|
+
undefined,
|
|
1141
|
+
undefined,
|
|
1142
|
+
iife,
|
|
1143
|
+
);
|
|
1144
|
+
context.setOriginal(declaration, classNode);
|
|
1145
|
+
statements.push(
|
|
1146
|
+
factory.createVariableStatement(
|
|
1147
|
+
undefined,
|
|
1148
|
+
factory.createVariableDeclarationList(factory.createNodeList([declaration]), NodeFlags.Let),
|
|
1149
|
+
),
|
|
1150
|
+
);
|
|
1151
|
+
const exportStatement = createExportDefault(factory, factory.getDeclarationName(classNode, NameOptions.None));
|
|
1152
|
+
context.setOriginal(exportStatement, classNode);
|
|
1153
|
+
context.assignCommentRange(exportStatement, classNode);
|
|
1154
|
+
context.setSourceMapRange(exportStatement, moveRangePastDecorators(classNode).pos, classNode.end);
|
|
1155
|
+
statements.push(exportStatement);
|
|
1156
|
+
} else {
|
|
1157
|
+
// export default (() => { ... })();
|
|
1158
|
+
const exportStatement = createExportDefault(factory, iife);
|
|
1159
|
+
context.setOriginal(exportStatement, classNode);
|
|
1160
|
+
context.assignCommentRange(exportStatement, classNode);
|
|
1161
|
+
context.setSourceMapRange(exportStatement, moveRangePastDecorators(classNode).pos, classNode.end);
|
|
1162
|
+
statements.push(exportStatement);
|
|
1163
|
+
}
|
|
1164
|
+
} else {
|
|
1165
|
+
// let C = (() => { ... })();
|
|
1166
|
+
const iife = this.transformClassLike(classNode);
|
|
1167
|
+
const modifiers = this.filterModifiers(classNode.modifiers, ModifierFilter.NoExport);
|
|
1168
|
+
const declarationName = factory.getLocalName(classNode, NameOptions.AllowSourceMaps);
|
|
1169
|
+
const declaration = factory.createVariableDeclaration(declarationName, undefined, undefined, iife);
|
|
1170
|
+
context.setOriginal(declaration, classNode);
|
|
1171
|
+
const statement = factory.createVariableStatement(
|
|
1172
|
+
modifiers,
|
|
1173
|
+
factory.createVariableDeclarationList(factory.createNodeList([declaration]), NodeFlags.Let),
|
|
1174
|
+
);
|
|
1175
|
+
context.setOriginal(statement, classNode);
|
|
1176
|
+
context.assignCommentRange(statement, classNode);
|
|
1177
|
+
statements.push(statement);
|
|
1178
|
+
if (isExport) {
|
|
1179
|
+
// export { C };
|
|
1180
|
+
const exportStatement = createExternalModuleExport(factory, declarationName);
|
|
1181
|
+
context.setOriginal(exportStatement, classNode);
|
|
1182
|
+
statements.push(exportStatement);
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
return singleOrMany(statements, factory);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
private visitClassExpression(node: ClassExpression): Node {
|
|
1189
|
+
if (isDecoratedClassLike(node)) {
|
|
1190
|
+
const iife = this.transformClassLike(node);
|
|
1191
|
+
this.context.setOriginal(iife, node);
|
|
1192
|
+
return iife;
|
|
1193
|
+
}
|
|
1194
|
+
const modifiers = this.filterModifiers(node.modifiers, ModifierFilter.NoDecorators);
|
|
1195
|
+
const heritageClauses = this.visitNodes(node.heritageClauses);
|
|
1196
|
+
this.enterClass(undefined);
|
|
1197
|
+
const members = this.visitList(node.members, ListVisit.ClassElements);
|
|
1198
|
+
this.exitClass();
|
|
1199
|
+
return this.factory.updateClassExpression(node, modifiers, node.name, undefined, heritageClauses, members);
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* The `__runInitializers()` call for instance extra initializers, when no instance field
|
|
1204
|
+
* initializer carries it.
|
|
1205
|
+
*/
|
|
1206
|
+
private prepareConstructor(info: ClassInfo): Node[] {
|
|
1207
|
+
if (info.pendingInstanceInitializers.length === 0) return [];
|
|
1208
|
+
const statements = [
|
|
1209
|
+
this.factory.createExpressionStatement(this.factory.inlineExpressions(info.pendingInstanceInitializers)!),
|
|
1210
|
+
];
|
|
1211
|
+
info.pendingInstanceInitializers = [];
|
|
1212
|
+
return statements;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/** Visits constructor statements, adding the initializers after the `super()` call `superPath` leads to. */
|
|
1216
|
+
private transformConstructorBody(
|
|
1217
|
+
statementsOut: Node[],
|
|
1218
|
+
statementsIn: Node[],
|
|
1219
|
+
statementOffset: number,
|
|
1220
|
+
superPath: number[],
|
|
1221
|
+
superPathDepth: number,
|
|
1222
|
+
initializerStatements: Node[],
|
|
1223
|
+
): Node[] {
|
|
1224
|
+
const superStatementIndex = superPath[superPathDepth];
|
|
1225
|
+
for (let i = statementOffset; i < superStatementIndex; i++)
|
|
1226
|
+
pushVisited(statementsOut, this.visitNode(statementsIn[i]));
|
|
1227
|
+
const superStatement = statementsIn[superStatementIndex];
|
|
1228
|
+
if (superStatement instanceof TryStatement) {
|
|
1229
|
+
const tryStatement = superStatement as TryStatement;
|
|
1230
|
+
const tryBlock = tryStatement.tryBlock;
|
|
1231
|
+
const tryStatements = this.transformConstructorBody(
|
|
1232
|
+
[],
|
|
1233
|
+
tryBlock.statements.nodes,
|
|
1234
|
+
0,
|
|
1235
|
+
superPath,
|
|
1236
|
+
superPathDepth + 1,
|
|
1237
|
+
initializerStatements,
|
|
1238
|
+
);
|
|
1239
|
+
// Keeps the original try block's range for source maps.
|
|
1240
|
+
const newTryBlock = this.factory.createBlock(tryStatements, true);
|
|
1241
|
+
newTryBlock.pos = tryBlock.pos;
|
|
1242
|
+
newTryBlock.end = tryBlock.end;
|
|
1243
|
+
let catchClause: CatchClause | undefined = undefined;
|
|
1244
|
+
if (tryStatement.catchClause !== undefined) catchClause = this.visitNode(tryStatement.catchClause) as CatchClause;
|
|
1245
|
+
let finallyBlock: Block | undefined = undefined;
|
|
1246
|
+
if (tryStatement.finallyBlock !== undefined) finallyBlock = this.visitNode(tryStatement.finallyBlock) as Block;
|
|
1247
|
+
const updated: Node = this.factory.updateTryStatement(tryStatement, newTryBlock, catchClause, finallyBlock);
|
|
1248
|
+
statementsOut.push(updated);
|
|
1249
|
+
} else {
|
|
1250
|
+
pushVisited(statementsOut, this.visitNode(superStatement));
|
|
1251
|
+
appendAll(statementsOut, initializerStatements);
|
|
1252
|
+
}
|
|
1253
|
+
for (let i = superStatementIndex + 1; i < statementsIn.length; i++)
|
|
1254
|
+
pushVisited(statementsOut, this.visitNode(statementsIn[i]));
|
|
1255
|
+
return statementsOut;
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
private visitConstructorDeclaration(node: ConstructorDeclaration): Node {
|
|
1259
|
+
this.enterClassElement(node);
|
|
1260
|
+
const modifiers = this.filterModifiers(node.modifiers, ModifierFilter.NoDecorators);
|
|
1261
|
+
const parameters = this.visitNodes(node.parameters)!;
|
|
1262
|
+
let body: Node | undefined = undefined;
|
|
1263
|
+
const originalBody = node.body;
|
|
1264
|
+
if (originalBody instanceof Block && this.classInfo !== undefined) {
|
|
1265
|
+
// Instance extra initializers go into the body.
|
|
1266
|
+
const initializerStatements = this.prepareConstructor(this.classInfo);
|
|
1267
|
+
if (initializerStatements.length > 0) {
|
|
1268
|
+
const statements: Node[] = [];
|
|
1269
|
+
const all = originalBody.statements.nodes;
|
|
1270
|
+
const prologueCount = countPrologueDirectives(all);
|
|
1271
|
+
for (let i = 0; i < prologueCount; i++) statements.push(all[i]);
|
|
1272
|
+
const rest = all.slice(prologueCount);
|
|
1273
|
+
const superPath = findSuperStatementIndexPath(rest, 0);
|
|
1274
|
+
if (superPath.length > 0)
|
|
1275
|
+
this.transformConstructorBody(statements, rest, 0, superPath, 0, initializerStatements);
|
|
1276
|
+
else {
|
|
1277
|
+
appendAll(statements, initializerStatements);
|
|
1278
|
+
appendAll(statements, this.visitArray(rest));
|
|
1279
|
+
}
|
|
1280
|
+
body = this.factory.createBlock(statements, true);
|
|
1281
|
+
this.context.setOriginal(body, originalBody);
|
|
1282
|
+
body.pos = originalBody.pos;
|
|
1283
|
+
body.end = originalBody.end;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
if (body === undefined) body = this.visitNode(originalBody);
|
|
1287
|
+
this.exitClassElement();
|
|
1288
|
+
return this.factory.updateConstructorDeclaration(
|
|
1289
|
+
node,
|
|
1290
|
+
modifiers,
|
|
1291
|
+
undefined,
|
|
1292
|
+
parameters,
|
|
1293
|
+
undefined,
|
|
1294
|
+
undefined,
|
|
1295
|
+
body,
|
|
1296
|
+
);
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
private finishClassElement(updated: Node, original: Node): Node {
|
|
1300
|
+
if (updated !== original) {
|
|
1301
|
+
// Source maps start past decorators and modifiers, but comments cover the original range.
|
|
1302
|
+
this.context.assignCommentRange(updated, original);
|
|
1303
|
+
this.context.setSourceMapRange(updated, moveRangePastDecorators(original).pos, original.end);
|
|
1304
|
+
}
|
|
1305
|
+
return updated;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
private partialTransformClassElement(
|
|
1309
|
+
member: Node,
|
|
1310
|
+
info: ClassInfo | undefined,
|
|
1311
|
+
descriptorKind: DescriptorKind,
|
|
1312
|
+
): PartialResult {
|
|
1313
|
+
const factory = this.factory;
|
|
1314
|
+
const context = this.context;
|
|
1315
|
+
const memberName = getName(member);
|
|
1316
|
+
if (info === undefined) {
|
|
1317
|
+
const result = new PartialResult(this.filterModifiers(getModifiers(member), ModifierFilter.NoDecorators));
|
|
1318
|
+
this.enterName();
|
|
1319
|
+
result.name = this.visitPropertyName(memberName);
|
|
1320
|
+
this.exitName();
|
|
1321
|
+
return result;
|
|
1322
|
+
}
|
|
1323
|
+
// Member decorators have privileged access to private names, but computed names are
|
|
1324
|
+
// evaluated interspersed with them, so decorator evaluation is inlined into the names.
|
|
1325
|
+
// Decorators are evaluated outside the class body, so `this` isn't `_classThis` there.
|
|
1326
|
+
const savedClassThis = this.classThis;
|
|
1327
|
+
this.classThis = undefined;
|
|
1328
|
+
const memberDecorators = this.transformAllDecoratorsOfDeclaration(getDecorators(member));
|
|
1329
|
+
this.classThis = savedClassThis;
|
|
1330
|
+
const modifiers = this.filterModifiers(getModifiers(member), ModifierFilter.NoDecorators);
|
|
1331
|
+
const result = new PartialResult(modifiers);
|
|
1332
|
+
if (memberDecorators.length > 0) {
|
|
1333
|
+
const memberDecoratorsName = this.createHelperVariable(member, 'decorators');
|
|
1334
|
+
const memberInfo = new MemberInfo(memberDecoratorsName);
|
|
1335
|
+
info.setMemberInfo(member, memberInfo);
|
|
1336
|
+
this.pendingExpressions.push(
|
|
1337
|
+
factory.createAssignment(
|
|
1338
|
+
memberDecoratorsName,
|
|
1339
|
+
factory.created(new ArrayLiteralExpression(factory.createNodeList(memberDecorators), false)),
|
|
1340
|
+
),
|
|
1341
|
+
);
|
|
1342
|
+
const kind =
|
|
1343
|
+
member.kind === SyntaxKind.GetAccessor
|
|
1344
|
+
? 'getter'
|
|
1345
|
+
: member.kind === SyntaxKind.SetAccessor
|
|
1346
|
+
? 'setter'
|
|
1347
|
+
: member.kind === SyntaxKind.MethodDeclaration
|
|
1348
|
+
? 'method'
|
|
1349
|
+
: isAutoAccessorPropertyDeclaration(member)
|
|
1350
|
+
? 'accessor'
|
|
1351
|
+
: 'field';
|
|
1352
|
+
let nameComputed = false;
|
|
1353
|
+
let nameExpression: Node | undefined = undefined;
|
|
1354
|
+
if (memberName instanceof Identifier || memberName instanceof PrivateIdentifier) nameExpression = memberName;
|
|
1355
|
+
else if (memberName !== undefined && isPropertyNameLiteral(memberName)) {
|
|
1356
|
+
nameComputed = true;
|
|
1357
|
+
nameExpression = factory.createStringLiteralFromNode(memberName);
|
|
1358
|
+
} else if (memberName instanceof ComputedPropertyName) {
|
|
1359
|
+
const expression = memberName.expression;
|
|
1360
|
+
nameComputed = true;
|
|
1361
|
+
if (isPropertyNameLiteral(expression) && !(expression instanceof Identifier))
|
|
1362
|
+
nameExpression = factory.createStringLiteralFromNode(expression);
|
|
1363
|
+
else {
|
|
1364
|
+
this.enterName();
|
|
1365
|
+
this.visitReferencedPropertyName(memberName, result);
|
|
1366
|
+
this.exitName();
|
|
1367
|
+
nameExpression = result.referencedName;
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
const isField = member.kind === SyntaxKind.PropertyDeclaration;
|
|
1371
|
+
const contextObject = this.createClassElementContextObject(
|
|
1372
|
+
kind,
|
|
1373
|
+
nameComputed,
|
|
1374
|
+
nameExpression!,
|
|
1375
|
+
isStatic(member),
|
|
1376
|
+
memberName instanceof PrivateIdentifier,
|
|
1377
|
+
isField || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.MethodDeclaration,
|
|
1378
|
+
isField || member.kind === SyntaxKind.SetAccessor,
|
|
1379
|
+
info.metadataReference,
|
|
1380
|
+
);
|
|
1381
|
+
if (isMethodOrAccessor(member)) {
|
|
1382
|
+
// __esDecorate(this, null | _member_descriptor = { value() { ... } }, _member_decorators, { kind: "method", ... }, null, _instanceExtraInitializers);
|
|
1383
|
+
const extraInitializersName = isStatic(member)
|
|
1384
|
+
? info.staticMethodExtraInitializersName!
|
|
1385
|
+
: info.instanceMethodExtraInitializersName!;
|
|
1386
|
+
let descriptor: Node;
|
|
1387
|
+
if (isPrivateIdentifierClassElementDeclaration(member) && descriptorKind !== DescriptorKind.None) {
|
|
1388
|
+
// A private member's body moves into a descriptor object, keeping only `async`.
|
|
1389
|
+
const descriptorObject = this.createDescriptorObject(
|
|
1390
|
+
descriptorKind,
|
|
1391
|
+
member,
|
|
1392
|
+
this.filterModifiers(modifiers, ModifierFilter.AsyncOnly),
|
|
1393
|
+
);
|
|
1394
|
+
memberInfo.descriptorName = this.createHelperVariable(member, 'descriptor');
|
|
1395
|
+
result.descriptorName = memberInfo.descriptorName;
|
|
1396
|
+
descriptor = factory.createAssignment(memberInfo.descriptorName, descriptorObject);
|
|
1397
|
+
} else descriptor = factory.createToken(SyntaxKind.NullKeyword);
|
|
1398
|
+
const statement = factory.createExpressionStatement(
|
|
1399
|
+
createESDecorateHelper(
|
|
1400
|
+
factory,
|
|
1401
|
+
factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
1402
|
+
descriptor,
|
|
1403
|
+
memberDecoratorsName,
|
|
1404
|
+
contextObject,
|
|
1405
|
+
factory.createToken(SyntaxKind.NullKeyword),
|
|
1406
|
+
extraInitializersName,
|
|
1407
|
+
),
|
|
1408
|
+
);
|
|
1409
|
+
context.setSourceMapRange(statement, moveRangePastDecorators(member).pos, member.end);
|
|
1410
|
+
this.appendDecorationStatement(info, member, statement);
|
|
1411
|
+
} else if (isField) {
|
|
1412
|
+
// __esDecorate(null | this, null | _member_descriptor = { get() { ... }, set(value) { ... } }, _member_decorators, { kind: "field", ... }, _member_initializers, _member_extraInitializers);
|
|
1413
|
+
memberInfo.initializersName = this.createHelperVariable(member, 'initializers');
|
|
1414
|
+
memberInfo.extraInitializersName = this.createHelperVariable(member, 'extraInitializers');
|
|
1415
|
+
result.initializersName = memberInfo.initializersName;
|
|
1416
|
+
result.extraInitializersName = memberInfo.extraInitializersName;
|
|
1417
|
+
if (isStatic(member)) result.thisArg = info.classThis;
|
|
1418
|
+
const ctor: Node = isAutoAccessorPropertyDeclaration(member)
|
|
1419
|
+
? factory.createKeywordExpression(SyntaxKind.ThisKeyword)
|
|
1420
|
+
: factory.createToken(SyntaxKind.NullKeyword);
|
|
1421
|
+
let descriptor: Node;
|
|
1422
|
+
if (
|
|
1423
|
+
isPrivateIdentifierClassElementDeclaration(member) &&
|
|
1424
|
+
hasSyntacticModifier(member, ModifierFlags.Accessor) &&
|
|
1425
|
+
descriptorKind !== DescriptorKind.None
|
|
1426
|
+
) {
|
|
1427
|
+
const descriptorObject = this.createDescriptorObject(descriptorKind, member, undefined);
|
|
1428
|
+
memberInfo.descriptorName = this.createHelperVariable(member, 'descriptor');
|
|
1429
|
+
result.descriptorName = memberInfo.descriptorName;
|
|
1430
|
+
descriptor = factory.createAssignment(memberInfo.descriptorName, descriptorObject);
|
|
1431
|
+
} else descriptor = factory.createToken(SyntaxKind.NullKeyword);
|
|
1432
|
+
const statement = factory.createExpressionStatement(
|
|
1433
|
+
createESDecorateHelper(
|
|
1434
|
+
factory,
|
|
1435
|
+
ctor,
|
|
1436
|
+
descriptor,
|
|
1437
|
+
memberDecoratorsName,
|
|
1438
|
+
contextObject,
|
|
1439
|
+
memberInfo.initializersName,
|
|
1440
|
+
memberInfo.extraInitializersName,
|
|
1441
|
+
),
|
|
1442
|
+
);
|
|
1443
|
+
context.setSourceMapRange(statement, moveRangePastDecorators(member).pos, member.end);
|
|
1444
|
+
this.appendDecorationStatement(info, member, statement);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
if (result.name === undefined) {
|
|
1448
|
+
this.enterName();
|
|
1449
|
+
result.name = this.visitPropertyName(memberName);
|
|
1450
|
+
this.exitName();
|
|
1451
|
+
}
|
|
1452
|
+
// Comments of methods and properties without modifiers would print twice on the name.
|
|
1453
|
+
if (
|
|
1454
|
+
(modifiers === undefined || modifiers.nodes.length === 0) &&
|
|
1455
|
+
(member.kind === SyntaxKind.MethodDeclaration || member.kind === SyntaxKind.PropertyDeclaration)
|
|
1456
|
+
)
|
|
1457
|
+
context.setEmitFlags(result.name!, EmitFlags.NoLeadingComments);
|
|
1458
|
+
return result;
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
private appendDecorationStatement(info: ClassInfo, member: Node, statement: Node): boolean {
|
|
1462
|
+
if (isMethodOrAccessor(member) || isAutoAccessorPropertyDeclaration(member)) {
|
|
1463
|
+
if (isStatic(member)) info.staticNonFieldDecorationStatements.push(statement);
|
|
1464
|
+
else info.nonStaticNonFieldDecorationStatements.push(statement);
|
|
1465
|
+
} else if (isStatic(member)) info.staticFieldDecorationStatements.push(statement);
|
|
1466
|
+
else info.nonStaticFieldDecorationStatements.push(statement);
|
|
1467
|
+
return true;
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
// Class elements
|
|
1471
|
+
|
|
1472
|
+
private visitMethodDeclaration(node: MethodDeclaration): Node {
|
|
1473
|
+
this.enterClassElement(node);
|
|
1474
|
+
const result = this.partialTransformClassElement(node, this.classInfo, DescriptorKind.Method);
|
|
1475
|
+
if (result.descriptorName !== undefined) {
|
|
1476
|
+
this.exitClassElement();
|
|
1477
|
+
return this.finishClassElement(
|
|
1478
|
+
this.createMethodDescriptorForwarder(result.modifiers, result.name!, result.descriptorName),
|
|
1479
|
+
node,
|
|
1480
|
+
);
|
|
1481
|
+
}
|
|
1482
|
+
const parameters = this.visitNodes(node.parameters)!;
|
|
1483
|
+
const body = this.visitNode(node.body);
|
|
1484
|
+
this.exitClassElement();
|
|
1485
|
+
return this.finishClassElement(
|
|
1486
|
+
this.factory.updateMethodDeclaration(
|
|
1487
|
+
node,
|
|
1488
|
+
result.modifiers,
|
|
1489
|
+
node.asteriskToken,
|
|
1490
|
+
result.name!,
|
|
1491
|
+
undefined,
|
|
1492
|
+
undefined,
|
|
1493
|
+
parameters,
|
|
1494
|
+
undefined,
|
|
1495
|
+
undefined,
|
|
1496
|
+
body,
|
|
1497
|
+
),
|
|
1498
|
+
node,
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
private visitGetAccessorDeclaration(node: GetAccessorDeclaration): Node {
|
|
1503
|
+
this.enterClassElement(node);
|
|
1504
|
+
const result = this.partialTransformClassElement(node, this.classInfo, DescriptorKind.GetAccessor);
|
|
1505
|
+
if (result.descriptorName !== undefined) {
|
|
1506
|
+
this.exitClassElement();
|
|
1507
|
+
return this.finishClassElement(
|
|
1508
|
+
this.createGetAccessorDescriptorForwarder(result.modifiers, result.name!, result.descriptorName),
|
|
1509
|
+
node,
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
const parameters = this.visitNodes(node.parameters)!;
|
|
1513
|
+
const body = this.visitNode(node.body);
|
|
1514
|
+
this.exitClassElement();
|
|
1515
|
+
return this.finishClassElement(
|
|
1516
|
+
this.factory.updateGetAccessorDeclaration(
|
|
1517
|
+
node,
|
|
1518
|
+
result.modifiers,
|
|
1519
|
+
result.name!,
|
|
1520
|
+
undefined,
|
|
1521
|
+
parameters,
|
|
1522
|
+
undefined,
|
|
1523
|
+
undefined,
|
|
1524
|
+
body,
|
|
1525
|
+
),
|
|
1526
|
+
node,
|
|
1527
|
+
);
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
private visitSetAccessorDeclaration(node: SetAccessorDeclaration): Node {
|
|
1531
|
+
this.enterClassElement(node);
|
|
1532
|
+
const result = this.partialTransformClassElement(node, this.classInfo, DescriptorKind.SetAccessor);
|
|
1533
|
+
if (result.descriptorName !== undefined) {
|
|
1534
|
+
this.exitClassElement();
|
|
1535
|
+
return this.finishClassElement(
|
|
1536
|
+
this.createSetAccessorDescriptorForwarder(result.modifiers, result.name!, result.descriptorName),
|
|
1537
|
+
node,
|
|
1538
|
+
);
|
|
1539
|
+
}
|
|
1540
|
+
const parameters = this.visitNodes(node.parameters)!;
|
|
1541
|
+
const body = this.visitNode(node.body);
|
|
1542
|
+
this.exitClassElement();
|
|
1543
|
+
return this.finishClassElement(
|
|
1544
|
+
this.factory.updateSetAccessorDeclaration(
|
|
1545
|
+
node,
|
|
1546
|
+
result.modifiers,
|
|
1547
|
+
result.name!,
|
|
1548
|
+
undefined,
|
|
1549
|
+
parameters,
|
|
1550
|
+
undefined,
|
|
1551
|
+
undefined,
|
|
1552
|
+
body,
|
|
1553
|
+
),
|
|
1554
|
+
node,
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
private visitClassStaticBlockDeclaration(node: ClassStaticBlockDeclaration): Node | undefined {
|
|
1559
|
+
const original: Node = node;
|
|
1560
|
+
this.enterClassElement(node);
|
|
1561
|
+
const factory = this.factory;
|
|
1562
|
+
const context = this.context;
|
|
1563
|
+
let result: Node;
|
|
1564
|
+
if (isClassNamedEvaluationHelperBlock(context, node)) {
|
|
1565
|
+
result = this.visitEachChild(node);
|
|
1566
|
+
// Keeps the block recognizable after `this` became `_classThis`.
|
|
1567
|
+
const assignedName = context.getAssignedName(node);
|
|
1568
|
+
if (assignedName !== undefined && result !== original) context.setAssignedName(result, assignedName);
|
|
1569
|
+
} else if (isClassThisAssignmentBlock(context, node)) {
|
|
1570
|
+
const savedClassThis = this.classThis;
|
|
1571
|
+
this.classThis = undefined;
|
|
1572
|
+
result = this.visitEachChild(node);
|
|
1573
|
+
this.classThis = savedClassThis;
|
|
1574
|
+
} else {
|
|
1575
|
+
// Temporaries of the block's contents stay scoped to the block.
|
|
1576
|
+
context.startVariableEnvironment();
|
|
1577
|
+
result = this.visitEachChild(node);
|
|
1578
|
+
const declarations = context.endVariableEnvironment();
|
|
1579
|
+
if (declarations.length > 0 && result instanceof ClassStaticBlockDeclaration) {
|
|
1580
|
+
const body = (result as ClassStaticBlockDeclaration).body;
|
|
1581
|
+
result = factory.created(
|
|
1582
|
+
new ClassStaticBlockDeclaration(
|
|
1583
|
+
undefined,
|
|
1584
|
+
factory.createBlock(declarations.concat(body.statements.nodes), body.multiLine),
|
|
1585
|
+
),
|
|
1586
|
+
);
|
|
1587
|
+
}
|
|
1588
|
+
const info = this.classInfo;
|
|
1589
|
+
if (info !== undefined) {
|
|
1590
|
+
info.hasStaticInitializers = true;
|
|
1591
|
+
if (info.pendingStaticInitializers.length > 0) {
|
|
1592
|
+
// Pending initializers get a block of their own, so names don't collide with this one's.
|
|
1593
|
+
const statements: Node[] = [];
|
|
1594
|
+
for (let i = 0; i < info.pendingStaticInitializers.length; i++) {
|
|
1595
|
+
const initializer = info.pendingStaticInitializers[i];
|
|
1596
|
+
const statement = factory.createExpressionStatement(initializer);
|
|
1597
|
+
context.setSourceMapRange(statement, context.sourceMapPos(initializer), context.sourceMapEnd(initializer));
|
|
1598
|
+
statements.push(statement);
|
|
1599
|
+
}
|
|
1600
|
+
const staticBlock = factory.created(
|
|
1601
|
+
new ClassStaticBlockDeclaration(undefined, factory.createBlock(statements, true)),
|
|
1602
|
+
);
|
|
1603
|
+
info.pendingStaticInitializers = [];
|
|
1604
|
+
this.exitClassElement();
|
|
1605
|
+
return singleOrMany([staticBlock, result], factory);
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
}
|
|
1609
|
+
this.exitClassElement();
|
|
1610
|
+
return result;
|
|
1611
|
+
}
|
|
1612
|
+
|
|
1613
|
+
private visitPropertyDeclaration(original: PropertyDeclaration): Node | undefined {
|
|
1614
|
+
const factory = this.factory;
|
|
1615
|
+
const context = this.context;
|
|
1616
|
+
let node = original;
|
|
1617
|
+
if (isNamedEvaluation(context, node, anonymousDecoratedClass))
|
|
1618
|
+
node = transformNamedEvaluation(
|
|
1619
|
+
context,
|
|
1620
|
+
node,
|
|
1621
|
+
canIgnoreEmptyStringLiteralInAssignedName(node.initializer),
|
|
1622
|
+
'',
|
|
1623
|
+
) as PropertyDeclaration;
|
|
1624
|
+
this.enterClassElement(node);
|
|
1625
|
+
const isAccessor = hasSyntacticModifier(node, ModifierFlags.Accessor);
|
|
1626
|
+
const result = this.partialTransformClassElement(
|
|
1627
|
+
node,
|
|
1628
|
+
this.classInfo,
|
|
1629
|
+
isAccessor ? DescriptorKind.AccessorProperty : DescriptorKind.None,
|
|
1630
|
+
);
|
|
1631
|
+
context.startVariableEnvironment();
|
|
1632
|
+
let initializer = this.visitNode(node.initializer);
|
|
1633
|
+
if (result.initializersName !== undefined)
|
|
1634
|
+
initializer = createRunInitializersHelper(
|
|
1635
|
+
factory,
|
|
1636
|
+
result.thisArg !== undefined ? result.thisArg : factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
1637
|
+
result.initializersName,
|
|
1638
|
+
initializer !== undefined ? initializer : factory.createVoidZero(),
|
|
1639
|
+
);
|
|
1640
|
+
const info = this.classInfo;
|
|
1641
|
+
if (isStatic(node) && info !== undefined && initializer !== undefined) info.hasStaticInitializers = true;
|
|
1642
|
+
const declarations = context.endVariableEnvironment();
|
|
1643
|
+
if (declarations.length > 0) {
|
|
1644
|
+
declarations.push(factory.createReturnStatement(initializer));
|
|
1645
|
+
initializer = factory.createImmediatelyInvokedArrowFunction(declarations);
|
|
1646
|
+
}
|
|
1647
|
+
if (info !== undefined) {
|
|
1648
|
+
if (isStatic(node)) {
|
|
1649
|
+
initializer = this.injectPendingInitializers(info, true, initializer);
|
|
1650
|
+
if (result.extraInitializersName !== undefined)
|
|
1651
|
+
info.pendingStaticInitializers.push(
|
|
1652
|
+
createRunInitializersHelper(
|
|
1653
|
+
factory,
|
|
1654
|
+
info.classThis !== undefined ? info.classThis : factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
1655
|
+
result.extraInitializersName,
|
|
1656
|
+
undefined,
|
|
1657
|
+
),
|
|
1658
|
+
);
|
|
1659
|
+
} else {
|
|
1660
|
+
initializer = this.injectPendingInitializers(info, false, initializer);
|
|
1661
|
+
if (result.extraInitializersName !== undefined)
|
|
1662
|
+
info.pendingInstanceInitializers.push(
|
|
1663
|
+
createRunInitializersHelper(
|
|
1664
|
+
factory,
|
|
1665
|
+
factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
1666
|
+
result.extraInitializersName,
|
|
1667
|
+
undefined,
|
|
1668
|
+
),
|
|
1669
|
+
);
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
this.exitClassElement();
|
|
1673
|
+
if (isAccessor && result.descriptorName !== undefined) {
|
|
1674
|
+
// `accessor #x = 1;` becomes a backing field and forwarders to the decorated descriptor:
|
|
1675
|
+
// #x_accessor_storage = 1;
|
|
1676
|
+
// get #x() { return _private_x_descriptor.get.call(this); }
|
|
1677
|
+
// set #x(value) { _private_x_descriptor.set.call(this, value); }
|
|
1678
|
+
const commentPos = context.commentPos(node);
|
|
1679
|
+
const commentEnd = context.commentEnd(node);
|
|
1680
|
+
const sourceMapPos = context.sourceMapPos(node);
|
|
1681
|
+
const sourceMapEnd = context.sourceMapEnd(node);
|
|
1682
|
+
// Two declarations replace one, so a computed name is cached.
|
|
1683
|
+
const propertyName = node.name;
|
|
1684
|
+
let getterName = result.name!;
|
|
1685
|
+
let setterName = result.name!;
|
|
1686
|
+
if (propertyName instanceof ComputedPropertyName && !isSimpleInlineableExpression(propertyName.expression)) {
|
|
1687
|
+
const cacheAssignment = findComputedPropertyNameCacheAssignment(propertyName);
|
|
1688
|
+
if (cacheAssignment !== undefined) {
|
|
1689
|
+
getterName = factory.updateComputedPropertyName(propertyName, this.visitNode(propertyName.expression)!);
|
|
1690
|
+
setterName = factory.updateComputedPropertyName(propertyName, cacheAssignment.left);
|
|
1691
|
+
} else {
|
|
1692
|
+
const temp = factory.createTempVariable(0);
|
|
1693
|
+
const expressionNode = propertyName.expression;
|
|
1694
|
+
context.setSourceMapRange(temp, expressionNode.pos, expressionNode.end);
|
|
1695
|
+
context.addVariableDeclaration(temp);
|
|
1696
|
+
const assignment = factory.createAssignment(temp, this.visitNode(expressionNode)!);
|
|
1697
|
+
context.setSourceMapRange(assignment, expressionNode.pos, expressionNode.end);
|
|
1698
|
+
getterName = factory.updateComputedPropertyName(propertyName, assignment);
|
|
1699
|
+
setterName = factory.updateComputedPropertyName(propertyName, temp);
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
const modifiers = this.filterModifiers(result.modifiers, ModifierFilter.NoAccessor);
|
|
1703
|
+
const backingField: Node = createAccessorPropertyBackingField(factory, node, modifiers, initializer);
|
|
1704
|
+
context.setOriginal(backingField, node);
|
|
1705
|
+
context.setEmitFlags(backingField, EmitFlags.NoComments);
|
|
1706
|
+
context.setSourceMapRange(backingField, sourceMapPos, sourceMapEnd);
|
|
1707
|
+
const backingFieldName = getName(backingField)!;
|
|
1708
|
+
context.setSourceMapRange(backingFieldName, context.sourceMapPos(node.name), context.sourceMapEnd(node.name));
|
|
1709
|
+
const getter = this.createGetAccessorDescriptorForwarder(modifiers, getterName, result.descriptorName);
|
|
1710
|
+
context.setOriginal(getter, node);
|
|
1711
|
+
context.setCommentRange(getter, commentPos, commentEnd);
|
|
1712
|
+
context.setSourceMapRange(getter, sourceMapPos, sourceMapEnd);
|
|
1713
|
+
const setter = this.createSetAccessorDescriptorForwarder(modifiers, setterName, result.descriptorName);
|
|
1714
|
+
context.setOriginal(setter, node);
|
|
1715
|
+
context.setEmitFlags(setter, EmitFlags.NoComments);
|
|
1716
|
+
context.setSourceMapRange(setter, sourceMapPos, sourceMapEnd);
|
|
1717
|
+
const declarations: Node[] = [];
|
|
1718
|
+
declarations.push(backingField);
|
|
1719
|
+
declarations.push(getter);
|
|
1720
|
+
declarations.push(setter);
|
|
1721
|
+
return factory.createSyntaxList(declarations);
|
|
1722
|
+
}
|
|
1723
|
+
return this.finishClassElement(
|
|
1724
|
+
factory.updatePropertyDeclaration(node, result.modifiers, result.name!, undefined, undefined, initializer),
|
|
1725
|
+
node,
|
|
1726
|
+
);
|
|
1727
|
+
}
|
|
1728
|
+
|
|
1729
|
+
// `super` and `this` in static initializers
|
|
1730
|
+
|
|
1731
|
+
private visitCallExpression(node: CallExpression): Node {
|
|
1732
|
+
if (isSuperProperty(node.expression) && this.classThis !== undefined) {
|
|
1733
|
+
const expression = this.visitNode(node.expression)!;
|
|
1734
|
+
const args = this.visitNodes(node.arguments)!;
|
|
1735
|
+
const invocation = this.factory.createFunctionCallCall(expression, this.classThis, args.nodes);
|
|
1736
|
+
this.context.setOriginal(invocation, node);
|
|
1737
|
+
invocation.pos = node.pos;
|
|
1738
|
+
invocation.end = node.end;
|
|
1739
|
+
return invocation;
|
|
1740
|
+
}
|
|
1741
|
+
return this.visitEachChild(node);
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
private visitTaggedTemplateExpression(node: TaggedTemplateExpression): Node {
|
|
1745
|
+
if (isSuperProperty(node.tag) && this.classThis !== undefined) {
|
|
1746
|
+
const tag = this.visitNode(node.tag)!;
|
|
1747
|
+
const boundTag = this.factory.createFunctionBindCall(tag, this.classThis, []);
|
|
1748
|
+
this.context.setOriginal(boundTag, node);
|
|
1749
|
+
boundTag.pos = node.pos;
|
|
1750
|
+
boundTag.end = node.end;
|
|
1751
|
+
const template = this.visitNode(node.template)!;
|
|
1752
|
+
return this.factory.updateTaggedTemplateExpression(node, boundTag, undefined, undefined, template, node.flags);
|
|
1753
|
+
}
|
|
1754
|
+
return this.visitEachChild(node);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
private visitPropertyAccessExpression(node: PropertyAccessExpression): Node {
|
|
1758
|
+
if (
|
|
1759
|
+
isSuperProperty(node) &&
|
|
1760
|
+
node.name instanceof Identifier &&
|
|
1761
|
+
this.classThis !== undefined &&
|
|
1762
|
+
this.classSuper !== undefined
|
|
1763
|
+
) {
|
|
1764
|
+
const superProperty = this.factory.createReflectGetCall(
|
|
1765
|
+
this.classSuper,
|
|
1766
|
+
this.factory.createStringLiteralFromNode(node.name),
|
|
1767
|
+
this.classThis,
|
|
1768
|
+
);
|
|
1769
|
+
this.context.setOriginal(superProperty, node.expression);
|
|
1770
|
+
superProperty.pos = node.expression.pos;
|
|
1771
|
+
superProperty.end = node.expression.end;
|
|
1772
|
+
return superProperty;
|
|
1773
|
+
}
|
|
1774
|
+
return this.visitEachChild(node);
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
private visitElementAccessExpression(node: ElementAccessExpression): Node {
|
|
1778
|
+
if (isSuperProperty(node) && this.classThis !== undefined && this.classSuper !== undefined) {
|
|
1779
|
+
const superProperty = this.factory.createReflectGetCall(
|
|
1780
|
+
this.classSuper,
|
|
1781
|
+
this.visitNode(node.argumentExpression)!,
|
|
1782
|
+
this.classThis,
|
|
1783
|
+
);
|
|
1784
|
+
this.context.setOriginal(superProperty, node.expression);
|
|
1785
|
+
superProperty.pos = node.expression.pos;
|
|
1786
|
+
superProperty.end = node.expression.end;
|
|
1787
|
+
return superProperty;
|
|
1788
|
+
}
|
|
1789
|
+
return this.visitEachChild(node);
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
// NamedEvaluation sites
|
|
1793
|
+
|
|
1794
|
+
private visitParameterDeclaration(original: ParameterDeclaration): Node {
|
|
1795
|
+
const context = this.context;
|
|
1796
|
+
let node = original;
|
|
1797
|
+
if (isNamedEvaluation(context, node, anonymousDecoratedClass))
|
|
1798
|
+
node = transformNamedEvaluation(
|
|
1799
|
+
context,
|
|
1800
|
+
node,
|
|
1801
|
+
canIgnoreEmptyStringLiteralInAssignedName(node.initializer),
|
|
1802
|
+
'',
|
|
1803
|
+
) as ParameterDeclaration;
|
|
1804
|
+
// Drops all modifiers, decorators included.
|
|
1805
|
+
const updated = this.factory.updateParameterDeclaration(
|
|
1806
|
+
node,
|
|
1807
|
+
undefined,
|
|
1808
|
+
node.dotDotDotToken,
|
|
1809
|
+
this.visitNode(node.name)!,
|
|
1810
|
+
undefined,
|
|
1811
|
+
undefined,
|
|
1812
|
+
this.visitNode(node.initializer),
|
|
1813
|
+
);
|
|
1814
|
+
if (updated !== node) {
|
|
1815
|
+
// Source maps start past the modifiers, but comments cover the original range.
|
|
1816
|
+
context.setCommentRange(updated, node.pos, node.end);
|
|
1817
|
+
const pos = moveRangePastModifiers(node).pos;
|
|
1818
|
+
updated.pos = pos | 0;
|
|
1819
|
+
updated.end = node.end;
|
|
1820
|
+
context.setSourceMapRange(updated, pos, node.end);
|
|
1821
|
+
context.setEmitFlags(updated.name, EmitFlags.NoTrailingSourceMap);
|
|
1822
|
+
}
|
|
1823
|
+
return updated;
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
private visitNamedEvaluationSite(node: Node, value: Node | undefined): Node {
|
|
1827
|
+
if (isNamedEvaluation(this.context, node, anonymousDecoratedClass))
|
|
1828
|
+
node = transformNamedEvaluation(this.context, node, canIgnoreEmptyStringLiteralInAssignedName(value), '');
|
|
1829
|
+
return this.visitEachChild(node);
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
private visitForStatement(node: ForStatement): Node {
|
|
1833
|
+
return this.factory.updateForStatement(
|
|
1834
|
+
node,
|
|
1835
|
+
this.visitDiscardedNode(node.initializer),
|
|
1836
|
+
this.visitNode(node.condition),
|
|
1837
|
+
this.visitDiscardedNode(node.incrementor),
|
|
1838
|
+
this.visitIterationBody(node.statement)!,
|
|
1839
|
+
);
|
|
1840
|
+
}
|
|
1841
|
+
|
|
1842
|
+
private visitBinaryExpression(node: BinaryExpression, discarded: boolean): Node {
|
|
1843
|
+
const factory = this.factory;
|
|
1844
|
+
const context = this.context;
|
|
1845
|
+
if (isDestructuringAssignment(node)) {
|
|
1846
|
+
const left = this.visitAssignmentPattern(node.left);
|
|
1847
|
+
const right = this.visitNode(node.right)!;
|
|
1848
|
+
return factory.updateBinaryExpression(node, undefined, left, undefined, node.operatorToken, right);
|
|
1849
|
+
}
|
|
1850
|
+
if (isAssignmentExpression(node, false)) {
|
|
1851
|
+
if (isNamedEvaluation(context, node, anonymousDecoratedClass))
|
|
1852
|
+
return this.visitEachChild(
|
|
1853
|
+
transformNamedEvaluation(context, node, canIgnoreEmptyStringLiteralInAssignedName(node.right), ''),
|
|
1854
|
+
);
|
|
1855
|
+
const left = node.left;
|
|
1856
|
+
if (isSuperProperty(left) && this.classThis !== undefined && this.classSuper !== undefined) {
|
|
1857
|
+
let setterName: Node | undefined = undefined;
|
|
1858
|
+
if (left instanceof ElementAccessExpression) setterName = this.visitNode(left.argumentExpression);
|
|
1859
|
+
else if (left instanceof PropertyAccessExpression && left.name instanceof Identifier)
|
|
1860
|
+
setterName = factory.createStringLiteralFromNode(left.name);
|
|
1861
|
+
if (setterName !== undefined) {
|
|
1862
|
+
// super.x = ... super.x += ... super[x] = ... super[x] += ...
|
|
1863
|
+
let expression = this.visitNode(node.right)!;
|
|
1864
|
+
if (isCompoundAssignment(node.operatorToken.kind)) {
|
|
1865
|
+
let getterName = setterName;
|
|
1866
|
+
if (!isSimpleInlineableExpression(setterName)) {
|
|
1867
|
+
const temp = factory.createTempVariable(0);
|
|
1868
|
+
context.addVariableDeclaration(temp);
|
|
1869
|
+
getterName = temp;
|
|
1870
|
+
setterName = factory.createAssignment(temp, setterName);
|
|
1871
|
+
}
|
|
1872
|
+
const superPropertyGet = factory.createReflectGetCall(this.classSuper, getterName, this.classThis);
|
|
1873
|
+
context.setOriginal(superPropertyGet, left);
|
|
1874
|
+
superPropertyGet.pos = left.pos;
|
|
1875
|
+
superPropertyGet.end = left.end;
|
|
1876
|
+
expression = factory.createBinaryExpression(
|
|
1877
|
+
superPropertyGet,
|
|
1878
|
+
getNonAssignmentOperatorForCompoundAssignment(node.operatorToken.kind),
|
|
1879
|
+
expression,
|
|
1880
|
+
);
|
|
1881
|
+
expression.pos = node.pos;
|
|
1882
|
+
expression.end = node.end;
|
|
1883
|
+
}
|
|
1884
|
+
let temp: Identifier | undefined = undefined;
|
|
1885
|
+
if (!discarded) {
|
|
1886
|
+
temp = factory.createTempVariable(0);
|
|
1887
|
+
context.addVariableDeclaration(temp);
|
|
1888
|
+
expression = factory.createAssignment(temp, expression);
|
|
1889
|
+
expression.pos = node.pos;
|
|
1890
|
+
expression.end = node.end;
|
|
1891
|
+
}
|
|
1892
|
+
expression = factory.createReflectSetCall(this.classSuper, setterName, expression, this.classThis);
|
|
1893
|
+
context.setOriginal(expression, node);
|
|
1894
|
+
expression.pos = node.pos;
|
|
1895
|
+
expression.end = node.end;
|
|
1896
|
+
if (temp !== undefined) {
|
|
1897
|
+
expression = factory.createCommaExpression(expression, temp);
|
|
1898
|
+
expression.pos = node.pos;
|
|
1899
|
+
expression.end = node.end;
|
|
1900
|
+
}
|
|
1901
|
+
return expression;
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
if (node.operatorToken.kind === SyntaxKind.CommaToken) {
|
|
1906
|
+
const left = this.visitDiscarded(node.left)!;
|
|
1907
|
+
const right = discarded ? this.visitDiscarded(node.right)! : this.visitNode(node.right)!;
|
|
1908
|
+
return factory.updateBinaryExpression(node, undefined, left, undefined, node.operatorToken, right);
|
|
1909
|
+
}
|
|
1910
|
+
return this.visitEachChild(node);
|
|
1911
|
+
}
|
|
1912
|
+
|
|
1913
|
+
private visitPreOrPostfixUnaryExpression(node: Node, discarded: boolean): Node {
|
|
1914
|
+
const factory = this.factory;
|
|
1915
|
+
const context = this.context;
|
|
1916
|
+
let operator = SyntaxKind.Unknown;
|
|
1917
|
+
let operandNode: Node | undefined = undefined;
|
|
1918
|
+
if (node instanceof PrefixUnaryExpression) {
|
|
1919
|
+
operator = node.operator;
|
|
1920
|
+
operandNode = node.operand;
|
|
1921
|
+
} else if (node instanceof PostfixUnaryExpression) {
|
|
1922
|
+
operator = node.operator;
|
|
1923
|
+
operandNode = node.operand;
|
|
1924
|
+
}
|
|
1925
|
+
if (
|
|
1926
|
+
operandNode !== undefined &&
|
|
1927
|
+
(operator === SyntaxKind.PlusPlusToken || operator === SyntaxKind.MinusMinusToken)
|
|
1928
|
+
) {
|
|
1929
|
+
const operand = skipParentheses(operandNode);
|
|
1930
|
+
if (isSuperProperty(operand) && this.classThis !== undefined && this.classSuper !== undefined) {
|
|
1931
|
+
let setterName: Node | undefined = undefined;
|
|
1932
|
+
if (operand instanceof ElementAccessExpression) setterName = this.visitNode(operand.argumentExpression);
|
|
1933
|
+
else if (operand instanceof PropertyAccessExpression && operand.name instanceof Identifier)
|
|
1934
|
+
setterName = factory.createStringLiteralFromNode(operand.name);
|
|
1935
|
+
if (setterName !== undefined) {
|
|
1936
|
+
let getterName = setterName;
|
|
1937
|
+
if (!isSimpleInlineableExpression(setterName)) {
|
|
1938
|
+
const temp = factory.createTempVariable(0);
|
|
1939
|
+
context.addVariableDeclaration(temp);
|
|
1940
|
+
getterName = temp;
|
|
1941
|
+
setterName = factory.createAssignment(temp, setterName);
|
|
1942
|
+
}
|
|
1943
|
+
let expression: Node = factory.createReflectGetCall(this.classSuper, getterName, this.classThis);
|
|
1944
|
+
context.setOriginal(expression, node);
|
|
1945
|
+
expression.pos = node.pos;
|
|
1946
|
+
expression.end = node.end;
|
|
1947
|
+
// A discarded result needs no temporary for it:
|
|
1948
|
+
// super.x++; => _a = Reflect.get(_super, "x"), _a++, Reflect.set(_super, "x", _a);
|
|
1949
|
+
// y = super.x++; => y = (_a = Reflect.get(_super, "x"), _b = _a++, Reflect.set(_super, "x", _a), _b);
|
|
1950
|
+
let temp: Identifier | undefined = undefined;
|
|
1951
|
+
if (!discarded) {
|
|
1952
|
+
temp = factory.createTempVariable(0);
|
|
1953
|
+
context.addVariableDeclaration(temp);
|
|
1954
|
+
}
|
|
1955
|
+
expression = expandPreOrPostfixIncrementOrDecrementExpression(context, node, expression, temp);
|
|
1956
|
+
expression = factory.createReflectSetCall(this.classSuper, setterName, expression, this.classThis);
|
|
1957
|
+
context.setOriginal(expression, node);
|
|
1958
|
+
expression.pos = node.pos;
|
|
1959
|
+
expression.end = node.end;
|
|
1960
|
+
if (temp !== undefined) {
|
|
1961
|
+
expression = factory.createCommaExpression(expression, temp);
|
|
1962
|
+
expression.pos = node.pos;
|
|
1963
|
+
expression.end = node.end;
|
|
1964
|
+
}
|
|
1965
|
+
return expression;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
return this.visitEachChild(node);
|
|
1970
|
+
}
|
|
1971
|
+
|
|
1972
|
+
// Property names
|
|
1973
|
+
|
|
1974
|
+
/** Sets the result's referenced name, for the decorator context, and its visited name. */
|
|
1975
|
+
private visitReferencedPropertyName(node: Node, result: PartialResult): boolean {
|
|
1976
|
+
const factory = this.factory;
|
|
1977
|
+
if (isPropertyNameLiteral(node) || node instanceof PrivateIdentifier) {
|
|
1978
|
+
result.referencedName = factory.createStringLiteralFromNode(node);
|
|
1979
|
+
result.name = this.visitNode(node);
|
|
1980
|
+
return true;
|
|
1981
|
+
}
|
|
1982
|
+
if (!(node instanceof ComputedPropertyName)) return false;
|
|
1983
|
+
const expression = node.expression;
|
|
1984
|
+
if (isPropertyNameLiteral(expression) && !(expression instanceof Identifier)) {
|
|
1985
|
+
result.referencedName = factory.createStringLiteralFromNode(expression);
|
|
1986
|
+
result.name = this.visitNode(node);
|
|
1987
|
+
return true;
|
|
1988
|
+
}
|
|
1989
|
+
const referencedName = factory.createGeneratedNameForNode(node, 0, '', '');
|
|
1990
|
+
this.context.addVariableDeclaration(referencedName);
|
|
1991
|
+
const key = createPropKeyHelper(factory, this.visitNode(expression)!);
|
|
1992
|
+
const assignment = factory.createAssignment(referencedName, key);
|
|
1993
|
+
result.referencedName = referencedName;
|
|
1994
|
+
result.name = factory.updateComputedPropertyName(node, this.injectPendingExpressions(assignment));
|
|
1995
|
+
return true;
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
private visitPropertyName(node: Node | undefined): Node | undefined {
|
|
1999
|
+
if (node instanceof ComputedPropertyName) return this.visitComputedPropertyName(node);
|
|
2000
|
+
return this.visitNode(node);
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
private visitComputedPropertyName(node: ComputedPropertyName): Node {
|
|
2004
|
+
let expression = this.visitNode(node.expression)!;
|
|
2005
|
+
if (!isSimpleInlineableExpression(expression)) expression = this.injectPendingExpressions(expression);
|
|
2006
|
+
return this.factory.updateComputedPropertyName(node, expression);
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
// Destructuring assignments
|
|
2010
|
+
|
|
2011
|
+
private visitDestructuringAssignmentTarget(node: Node): Node {
|
|
2012
|
+
if (node instanceof ObjectLiteralExpression || node instanceof ArrayLiteralExpression)
|
|
2013
|
+
return this.visitAssignmentPattern(node);
|
|
2014
|
+
if (isSuperProperty(node) && this.classThis !== undefined && this.classSuper !== undefined) {
|
|
2015
|
+
const factory = this.factory;
|
|
2016
|
+
let propertyName: Node | undefined = undefined;
|
|
2017
|
+
if (node instanceof ElementAccessExpression) propertyName = this.visitNode(node.argumentExpression);
|
|
2018
|
+
else if (node instanceof PropertyAccessExpression && node.name instanceof Identifier)
|
|
2019
|
+
propertyName = factory.createStringLiteralFromNode(node.name);
|
|
2020
|
+
if (propertyName !== undefined) {
|
|
2021
|
+
const paramName = factory.createTempVariable(0);
|
|
2022
|
+
const expression = factory.createAssignmentTargetWrapper(
|
|
2023
|
+
paramName,
|
|
2024
|
+
factory.createReflectSetCall(this.classSuper, propertyName, paramName, this.classThis),
|
|
2025
|
+
);
|
|
2026
|
+
this.context.setOriginal(expression, node);
|
|
2027
|
+
expression.pos = node.pos;
|
|
2028
|
+
expression.end = node.end;
|
|
2029
|
+
return expression;
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
return this.visitEachChild(node);
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
private visitAssignmentElement(node: Node): Node {
|
|
2036
|
+
if (node instanceof BinaryExpression && isAssignmentExpression(node, true)) {
|
|
2037
|
+
let assignment = node as BinaryExpression;
|
|
2038
|
+
if (isNamedEvaluation(this.context, assignment, anonymousDecoratedClass))
|
|
2039
|
+
assignment = transformNamedEvaluation(
|
|
2040
|
+
this.context,
|
|
2041
|
+
assignment,
|
|
2042
|
+
canIgnoreEmptyStringLiteralInAssignedName(assignment.right),
|
|
2043
|
+
'',
|
|
2044
|
+
) as BinaryExpression;
|
|
2045
|
+
const target = this.visitDestructuringAssignmentTarget(assignment.left);
|
|
2046
|
+
const initializer = this.visitNode(assignment.right)!;
|
|
2047
|
+
return this.factory.updateBinaryExpression(
|
|
2048
|
+
assignment,
|
|
2049
|
+
undefined,
|
|
2050
|
+
target,
|
|
2051
|
+
undefined,
|
|
2052
|
+
assignment.operatorToken,
|
|
2053
|
+
initializer,
|
|
2054
|
+
);
|
|
2055
|
+
}
|
|
2056
|
+
return this.visitDestructuringAssignmentTarget(node);
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2059
|
+
private visitArrayAssignmentElement(node: Node): Node | undefined {
|
|
2060
|
+
if (node instanceof SpreadElement) {
|
|
2061
|
+
const spread = node as SpreadElement;
|
|
2062
|
+
if (isLeftHandSideExpression(spread.expression))
|
|
2063
|
+
return this.factory.updateSpreadElement(spread, this.visitDestructuringAssignmentTarget(spread.expression));
|
|
2064
|
+
return this.visitEachChild(node);
|
|
2065
|
+
}
|
|
2066
|
+
if (node.kind !== SyntaxKind.OmittedExpression) return this.visitAssignmentElement(node);
|
|
2067
|
+
return this.visitEachChild(node);
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
private visitObjectAssignmentElement(node: Node): Node | undefined {
|
|
2071
|
+
const factory = this.factory;
|
|
2072
|
+
if (node instanceof SpreadAssignment) {
|
|
2073
|
+
const spread = node as SpreadAssignment;
|
|
2074
|
+
if (isLeftHandSideExpression(spread.expression))
|
|
2075
|
+
return factory.updateSpreadAssignment(spread, this.visitDestructuringAssignmentTarget(spread.expression));
|
|
2076
|
+
return this.visitEachChild(node);
|
|
2077
|
+
}
|
|
2078
|
+
if (node instanceof ShorthandPropertyAssignment) {
|
|
2079
|
+
const shorthand = node as ShorthandPropertyAssignment;
|
|
2080
|
+
let property: Node = shorthand;
|
|
2081
|
+
if (isNamedEvaluation(this.context, shorthand, anonymousDecoratedClass))
|
|
2082
|
+
property = transformNamedEvaluation(
|
|
2083
|
+
this.context,
|
|
2084
|
+
shorthand,
|
|
2085
|
+
canIgnoreEmptyStringLiteralInAssignedName(shorthand.objectAssignmentInitializer),
|
|
2086
|
+
'',
|
|
2087
|
+
);
|
|
2088
|
+
return this.visitEachChild(property);
|
|
2089
|
+
}
|
|
2090
|
+
if (node instanceof PropertyAssignment) {
|
|
2091
|
+
const property = node as PropertyAssignment;
|
|
2092
|
+
const name = this.visitNode(property.name)!;
|
|
2093
|
+
if (isAssignmentExpression(property.initializer, true))
|
|
2094
|
+
return factory.updatePropertyAssignment(
|
|
2095
|
+
property,
|
|
2096
|
+
undefined,
|
|
2097
|
+
name,
|
|
2098
|
+
undefined,
|
|
2099
|
+
undefined,
|
|
2100
|
+
this.visitAssignmentElement(property.initializer),
|
|
2101
|
+
);
|
|
2102
|
+
if (isLeftHandSideExpression(property.initializer))
|
|
2103
|
+
return factory.updatePropertyAssignment(
|
|
2104
|
+
property,
|
|
2105
|
+
undefined,
|
|
2106
|
+
name,
|
|
2107
|
+
undefined,
|
|
2108
|
+
undefined,
|
|
2109
|
+
this.visitDestructuringAssignmentTarget(property.initializer),
|
|
2110
|
+
);
|
|
2111
|
+
}
|
|
2112
|
+
return this.visitEachChild(node);
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
private visitAssignmentPattern(node: Node): Node {
|
|
2116
|
+
if (node instanceof ArrayLiteralExpression) {
|
|
2117
|
+
const array = node as ArrayLiteralExpression;
|
|
2118
|
+
return this.factory.updateArrayLiteralExpression(
|
|
2119
|
+
array,
|
|
2120
|
+
this.visitList(array.elements, ListVisit.ArrayAssignmentElements),
|
|
2121
|
+
array.multiLine,
|
|
2122
|
+
);
|
|
2123
|
+
}
|
|
2124
|
+
if (node instanceof ObjectLiteralExpression) {
|
|
2125
|
+
const object = node as ObjectLiteralExpression;
|
|
2126
|
+
return this.factory.updateObjectLiteralExpression(
|
|
2127
|
+
object,
|
|
2128
|
+
this.visitList(object.properties, ListVisit.ObjectAssignmentElements),
|
|
2129
|
+
object.multiLine,
|
|
2130
|
+
);
|
|
2131
|
+
}
|
|
2132
|
+
return node;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
private visitParenthesizedExpression(node: ParenthesizedExpression, discarded: boolean): Node {
|
|
2136
|
+
const expression = discarded ? this.visitDiscarded(node.expression)! : this.visitNode(node.expression)!;
|
|
2137
|
+
return this.factory.updateParenthesizedExpression(node, expression);
|
|
2138
|
+
}
|
|
2139
|
+
|
|
2140
|
+
private visitPartiallyEmittedExpression(node: PartiallyEmittedExpression, discarded: boolean): Node {
|
|
2141
|
+
const expression = discarded ? this.visitDiscarded(node.expression)! : this.visitNode(node.expression)!;
|
|
2142
|
+
return this.factory.updatePartiallyEmittedExpression(node, expression);
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
// Pending expressions
|
|
2146
|
+
|
|
2147
|
+
/** `pending` evaluated before `expression`, inside its parentheses. */
|
|
2148
|
+
private prependExpressions(pending: Node[], expression: Node | undefined): Node | undefined {
|
|
2149
|
+
const factory = this.factory;
|
|
2150
|
+
if (pending.length === 0) return expression;
|
|
2151
|
+
if (expression === undefined) return factory.inlineExpressions(pending);
|
|
2152
|
+
if (expression instanceof ParenthesizedExpression)
|
|
2153
|
+
return factory.updateParenthesizedExpression(
|
|
2154
|
+
expression,
|
|
2155
|
+
factory.inlineExpressions(pending.concat([expression.expression]))!,
|
|
2156
|
+
);
|
|
2157
|
+
return factory.inlineExpressions(pending.concat([expression]));
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
private injectPendingExpressions(expression: Node): Node {
|
|
2161
|
+
const result = this.prependExpressions(this.pendingExpressions, expression)!;
|
|
2162
|
+
if (result !== expression) this.pendingExpressions = [];
|
|
2163
|
+
return result;
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
private injectPendingInitializers(
|
|
2167
|
+
info: ClassInfo,
|
|
2168
|
+
isStaticMember: boolean,
|
|
2169
|
+
expression: Node | undefined,
|
|
2170
|
+
): Node | undefined {
|
|
2171
|
+
if (isStaticMember) {
|
|
2172
|
+
const result = this.prependExpressions(info.pendingStaticInitializers, expression);
|
|
2173
|
+
if (result !== expression) info.pendingStaticInitializers = [];
|
|
2174
|
+
return result;
|
|
2175
|
+
}
|
|
2176
|
+
const result = this.prependExpressions(info.pendingInstanceInitializers, expression);
|
|
2177
|
+
if (result !== expression) info.pendingInstanceInitializers = [];
|
|
2178
|
+
return result;
|
|
2179
|
+
}
|
|
2180
|
+
|
|
2181
|
+
// Decorators
|
|
2182
|
+
|
|
2183
|
+
private transformAllDecoratorsOfDeclaration(decorators: Node[]): Node[] {
|
|
2184
|
+
const result: Node[] = [];
|
|
2185
|
+
for (let i = 0; i < decorators.length; i++) {
|
|
2186
|
+
const decorator = decorators[i];
|
|
2187
|
+
if (decorator instanceof Decorator) result.push(this.transformDecorator(decorator as Decorator));
|
|
2188
|
+
}
|
|
2189
|
+
return result;
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
private transformDecorator(decorator: Decorator): Node {
|
|
2193
|
+
const expression = this.visitNode(decorator.expression)!;
|
|
2194
|
+
this.context.setEmitFlags(expression, EmitFlags.NoComments);
|
|
2195
|
+
// An access expression keeps its `this`.
|
|
2196
|
+
const inner = skipOuterExpressions(expression, OuterExpressionKinds.All);
|
|
2197
|
+
if (inner instanceof PropertyAccessExpression || inner instanceof ElementAccessExpression) {
|
|
2198
|
+
const bound = this.createCallBinding(expression);
|
|
2199
|
+
return this.context.factory.restoreOuterExpressions(
|
|
2200
|
+
expression,
|
|
2201
|
+
this.factory.createFunctionBindCall(bound.target, bound.thisArg, []),
|
|
2202
|
+
OuterExpressionKinds.All,
|
|
2203
|
+
);
|
|
2204
|
+
}
|
|
2205
|
+
return expression;
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
private createCallBinding(expression: Node): CallBinding {
|
|
2209
|
+
const factory = this.factory;
|
|
2210
|
+
const callee = skipOuterExpressions(expression, OuterExpressionKinds.All);
|
|
2211
|
+
if (isSuperProperty(callee) || callee.kind === SyntaxKind.SuperKeyword)
|
|
2212
|
+
return new CallBinding(callee, factory.createKeywordExpression(SyntaxKind.ThisKeyword));
|
|
2213
|
+
if ((this.context.getEmitFlags(callee) & EmitFlags.HelperName) !== 0)
|
|
2214
|
+
return new CallBinding(callee, factory.createVoidZero());
|
|
2215
|
+
if (callee instanceof PropertyAccessExpression) {
|
|
2216
|
+
if (shouldBeCapturedInTempVariable(callee.expression)) {
|
|
2217
|
+
const thisArg = factory.createTempVariable(0);
|
|
2218
|
+
this.context.addVariableDeclaration(thisArg);
|
|
2219
|
+
const assignment = factory.createAssignment(thisArg, callee.expression);
|
|
2220
|
+
assignment.pos = callee.expression.pos;
|
|
2221
|
+
assignment.end = callee.expression.end;
|
|
2222
|
+
const target = factory.createPropertyAccessExpression(assignment, callee.name);
|
|
2223
|
+
target.pos = callee.pos;
|
|
2224
|
+
target.end = callee.end;
|
|
2225
|
+
return new CallBinding(target, thisArg);
|
|
2226
|
+
}
|
|
2227
|
+
return new CallBinding(callee, callee.expression);
|
|
2228
|
+
}
|
|
2229
|
+
if (callee instanceof ElementAccessExpression) {
|
|
2230
|
+
if (shouldBeCapturedInTempVariable(callee.expression)) {
|
|
2231
|
+
const thisArg = factory.createTempVariable(0);
|
|
2232
|
+
this.context.addVariableDeclaration(thisArg);
|
|
2233
|
+
const assignment = factory.createAssignment(thisArg, callee.expression);
|
|
2234
|
+
assignment.pos = callee.expression.pos;
|
|
2235
|
+
assignment.end = callee.expression.end;
|
|
2236
|
+
const target = factory.createElementAccessExpression(assignment, callee.argumentExpression);
|
|
2237
|
+
target.pos = callee.pos;
|
|
2238
|
+
target.end = callee.end;
|
|
2239
|
+
return new CallBinding(target, thisArg);
|
|
2240
|
+
}
|
|
2241
|
+
return new CallBinding(callee, callee.expression);
|
|
2242
|
+
}
|
|
2243
|
+
return new CallBinding(expression, factory.createVoidZero());
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
// Pseudo-descriptors of private elements
|
|
2247
|
+
|
|
2248
|
+
/** A `value`, `get` or `set` method of a pseudo-descriptor: `kind: __setFunctionName(function () {}, "#x")`. */
|
|
2249
|
+
private createDescriptorMethod(
|
|
2250
|
+
original: Node,
|
|
2251
|
+
name: Node,
|
|
2252
|
+
modifiers: ModifierList | undefined,
|
|
2253
|
+
asteriskToken: Token | undefined,
|
|
2254
|
+
kind: string,
|
|
2255
|
+
parameters: NodeList,
|
|
2256
|
+
body: Node | undefined,
|
|
2257
|
+
): Node {
|
|
2258
|
+
const factory = this.factory;
|
|
2259
|
+
const context = this.context;
|
|
2260
|
+
const fn = factory.created(
|
|
2261
|
+
new FunctionExpression(
|
|
2262
|
+
modifiers,
|
|
2263
|
+
asteriskToken,
|
|
2264
|
+
undefined,
|
|
2265
|
+
undefined,
|
|
2266
|
+
parameters,
|
|
2267
|
+
undefined,
|
|
2268
|
+
undefined,
|
|
2269
|
+
body !== undefined ? body : factory.createBlock([], false),
|
|
2270
|
+
),
|
|
2271
|
+
);
|
|
2272
|
+
context.setOriginal(fn, original);
|
|
2273
|
+
context.setSourceMapRange(fn, moveRangePastDecorators(original).pos, original.end);
|
|
2274
|
+
context.setEmitFlags(fn, EmitFlags.NoComments);
|
|
2275
|
+
const prefix = kind === 'get' || kind === 'set' ? kind : '';
|
|
2276
|
+
const named = createSetFunctionNameHelper(factory, fn, factory.createStringLiteralFromNode(name), prefix);
|
|
2277
|
+
const method = factory.createPropertyAssignment(factory.createIdentifier(kind), named);
|
|
2278
|
+
context.setOriginal(method, original);
|
|
2279
|
+
context.setSourceMapRange(method, moveRangePastDecorators(original).pos, original.end);
|
|
2280
|
+
context.setEmitFlags(method, EmitFlags.NoComments);
|
|
2281
|
+
return method;
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
private createDescriptorObject(kind: DescriptorKind, member: Node, modifiers: ModifierList | undefined): Node {
|
|
2285
|
+
const factory = this.factory;
|
|
2286
|
+
const name = getName(member)!;
|
|
2287
|
+
const methods: Node[] = [];
|
|
2288
|
+
switch (kind) {
|
|
2289
|
+
case DescriptorKind.Method: {
|
|
2290
|
+
const parameters = this.visitNodes(getParameters(member))!;
|
|
2291
|
+
const body = this.visitNode(getBody(member));
|
|
2292
|
+
const asterisk = member instanceof MethodDeclaration ? (member as MethodDeclaration).asteriskToken : undefined;
|
|
2293
|
+
methods.push(this.createDescriptorMethod(member, name, modifiers, asterisk, 'value', parameters, body));
|
|
2294
|
+
break;
|
|
2295
|
+
}
|
|
2296
|
+
case DescriptorKind.GetAccessor: {
|
|
2297
|
+
const body = this.visitNode(getBody(member));
|
|
2298
|
+
methods.push(
|
|
2299
|
+
this.createDescriptorMethod(member, name, modifiers, undefined, 'get', factory.createNodeList([]), body),
|
|
2300
|
+
);
|
|
2301
|
+
break;
|
|
2302
|
+
}
|
|
2303
|
+
case DescriptorKind.SetAccessor: {
|
|
2304
|
+
const parameters = this.visitNodes(getParameters(member))!;
|
|
2305
|
+
const body = this.visitNode(getBody(member));
|
|
2306
|
+
methods.push(this.createDescriptorMethod(member, name, modifiers, undefined, 'set', parameters, body));
|
|
2307
|
+
break;
|
|
2308
|
+
}
|
|
2309
|
+
case DescriptorKind.AccessorProperty: {
|
|
2310
|
+
// { get() { return this.#x_accessor_storage; }, set(value) { this.#x_accessor_storage = value; } }
|
|
2311
|
+
const storage = factory.createGeneratedPrivateNameForNode(name, '', '_accessor_storage');
|
|
2312
|
+
const self = factory.createKeywordExpression(SyntaxKind.ThisKeyword);
|
|
2313
|
+
methods.push(
|
|
2314
|
+
this.createDescriptorMethod(
|
|
2315
|
+
member,
|
|
2316
|
+
name,
|
|
2317
|
+
undefined,
|
|
2318
|
+
undefined,
|
|
2319
|
+
'get',
|
|
2320
|
+
factory.createNodeList([]),
|
|
2321
|
+
factory.createBlock(
|
|
2322
|
+
[factory.createReturnStatement(factory.createPropertyAccessExpression(self, storage))],
|
|
2323
|
+
false,
|
|
2324
|
+
),
|
|
2325
|
+
),
|
|
2326
|
+
);
|
|
2327
|
+
methods.push(
|
|
2328
|
+
this.createDescriptorMethod(
|
|
2329
|
+
member,
|
|
2330
|
+
name,
|
|
2331
|
+
undefined,
|
|
2332
|
+
undefined,
|
|
2333
|
+
'set',
|
|
2334
|
+
factory.createNodeList([factory.createParameter(factory.createIdentifier('value'))]),
|
|
2335
|
+
factory.createBlock(
|
|
2336
|
+
[
|
|
2337
|
+
factory.createExpressionStatement(
|
|
2338
|
+
factory.createAssignment(
|
|
2339
|
+
factory.createPropertyAccessExpression(
|
|
2340
|
+
factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
2341
|
+
storage,
|
|
2342
|
+
),
|
|
2343
|
+
factory.createIdentifier('value'),
|
|
2344
|
+
),
|
|
2345
|
+
),
|
|
2346
|
+
],
|
|
2347
|
+
false,
|
|
2348
|
+
),
|
|
2349
|
+
),
|
|
2350
|
+
);
|
|
2351
|
+
break;
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
return factory.createObjectLiteral(methods, false);
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
/** `get name() { return _descriptor.value; }` */
|
|
2358
|
+
private createMethodDescriptorForwarder(
|
|
2359
|
+
modifiers: ModifierList | undefined,
|
|
2360
|
+
name: Node,
|
|
2361
|
+
descriptorName: Identifier,
|
|
2362
|
+
): Node {
|
|
2363
|
+
const factory = this.factory;
|
|
2364
|
+
return factory.created(
|
|
2365
|
+
new GetAccessorDeclaration(
|
|
2366
|
+
this.filterModifiers(modifiers, ModifierFilter.StaticOnly),
|
|
2367
|
+
name,
|
|
2368
|
+
undefined,
|
|
2369
|
+
factory.createNodeList([]),
|
|
2370
|
+
undefined,
|
|
2371
|
+
undefined,
|
|
2372
|
+
factory.createBlock(
|
|
2373
|
+
[
|
|
2374
|
+
factory.createReturnStatement(
|
|
2375
|
+
factory.createPropertyAccessExpression(descriptorName, factory.createIdentifier('value')),
|
|
2376
|
+
),
|
|
2377
|
+
],
|
|
2378
|
+
false,
|
|
2379
|
+
),
|
|
2380
|
+
),
|
|
2381
|
+
);
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
/** `get name() { return _descriptor.get.call(this); }` */
|
|
2385
|
+
private createGetAccessorDescriptorForwarder(
|
|
2386
|
+
modifiers: ModifierList | undefined,
|
|
2387
|
+
name: Node,
|
|
2388
|
+
descriptorName: Identifier,
|
|
2389
|
+
): Node {
|
|
2390
|
+
const factory = this.factory;
|
|
2391
|
+
return factory.created(
|
|
2392
|
+
new GetAccessorDeclaration(
|
|
2393
|
+
this.filterModifiers(modifiers, ModifierFilter.StaticOnly),
|
|
2394
|
+
name,
|
|
2395
|
+
undefined,
|
|
2396
|
+
factory.createNodeList([]),
|
|
2397
|
+
undefined,
|
|
2398
|
+
undefined,
|
|
2399
|
+
factory.createBlock(
|
|
2400
|
+
[
|
|
2401
|
+
factory.createReturnStatement(
|
|
2402
|
+
factory.createFunctionCallCall(
|
|
2403
|
+
factory.createPropertyAccessExpression(descriptorName, factory.createIdentifier('get')),
|
|
2404
|
+
factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
2405
|
+
[],
|
|
2406
|
+
),
|
|
2407
|
+
),
|
|
2408
|
+
],
|
|
2409
|
+
false,
|
|
2410
|
+
),
|
|
2411
|
+
),
|
|
2412
|
+
);
|
|
2413
|
+
}
|
|
2414
|
+
|
|
2415
|
+
/** `set name(value) { return _descriptor.set.call(this, value); }` */
|
|
2416
|
+
private createSetAccessorDescriptorForwarder(
|
|
2417
|
+
modifiers: ModifierList | undefined,
|
|
2418
|
+
name: Node,
|
|
2419
|
+
descriptorName: Identifier,
|
|
2420
|
+
): Node {
|
|
2421
|
+
const factory = this.factory;
|
|
2422
|
+
return factory.created(
|
|
2423
|
+
new SetAccessorDeclaration(
|
|
2424
|
+
this.filterModifiers(modifiers, ModifierFilter.StaticOnly),
|
|
2425
|
+
name,
|
|
2426
|
+
undefined,
|
|
2427
|
+
factory.createNodeList([factory.createParameter(factory.createIdentifier('value'))]),
|
|
2428
|
+
undefined,
|
|
2429
|
+
undefined,
|
|
2430
|
+
factory.createBlock(
|
|
2431
|
+
[
|
|
2432
|
+
factory.createReturnStatement(
|
|
2433
|
+
factory.createFunctionCallCall(
|
|
2434
|
+
factory.createPropertyAccessExpression(descriptorName, factory.createIdentifier('set')),
|
|
2435
|
+
factory.createKeywordExpression(SyntaxKind.ThisKeyword),
|
|
2436
|
+
[factory.createIdentifier('value')],
|
|
2437
|
+
),
|
|
2438
|
+
),
|
|
2439
|
+
],
|
|
2440
|
+
false,
|
|
2441
|
+
),
|
|
2442
|
+
),
|
|
2443
|
+
);
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2446
|
+
// Decorator contexts and metadata
|
|
2447
|
+
|
|
2448
|
+
private createClassElementContextObject(
|
|
2449
|
+
kind: string,
|
|
2450
|
+
nameComputed: boolean,
|
|
2451
|
+
name: Node,
|
|
2452
|
+
isStaticMember: boolean,
|
|
2453
|
+
isPrivate: boolean,
|
|
2454
|
+
hasGet: boolean,
|
|
2455
|
+
hasSet: boolean,
|
|
2456
|
+
metadata: Identifier,
|
|
2457
|
+
): Node {
|
|
2458
|
+
const factory = this.factory;
|
|
2459
|
+
const nameValue: Node =
|
|
2460
|
+
!nameComputed && (name instanceof Identifier || name instanceof PrivateIdentifier)
|
|
2461
|
+
? factory.createStringLiteralFromNode(name)
|
|
2462
|
+
: name;
|
|
2463
|
+
// `has` checks `name in obj`; `get` and `set` access `obj.name` or `obj[name]`.
|
|
2464
|
+
const access: Node[] = [
|
|
2465
|
+
factory.createPropertyAssignment(
|
|
2466
|
+
factory.createIdentifier('has'),
|
|
2467
|
+
factory.createArrowFunction(
|
|
2468
|
+
[factory.createParameter(factory.createIdentifier('obj'))],
|
|
2469
|
+
factory.createBinaryExpression(
|
|
2470
|
+
!nameComputed && name instanceof Identifier ? (factory.createStringLiteralFromNode(name) as Node) : name,
|
|
2471
|
+
SyntaxKind.InKeyword,
|
|
2472
|
+
factory.createIdentifier('obj'),
|
|
2473
|
+
),
|
|
2474
|
+
),
|
|
2475
|
+
),
|
|
2476
|
+
];
|
|
2477
|
+
if (hasGet)
|
|
2478
|
+
access.push(
|
|
2479
|
+
factory.createPropertyAssignment(
|
|
2480
|
+
factory.createIdentifier('get'),
|
|
2481
|
+
factory.createArrowFunction(
|
|
2482
|
+
[factory.createParameter(factory.createIdentifier('obj'))],
|
|
2483
|
+
this.createAccess(nameComputed, name),
|
|
2484
|
+
),
|
|
2485
|
+
),
|
|
2486
|
+
);
|
|
2487
|
+
if (hasSet)
|
|
2488
|
+
access.push(
|
|
2489
|
+
factory.createPropertyAssignment(
|
|
2490
|
+
factory.createIdentifier('set'),
|
|
2491
|
+
factory.createArrowFunction(
|
|
2492
|
+
[
|
|
2493
|
+
factory.createParameter(factory.createIdentifier('obj')),
|
|
2494
|
+
factory.createParameter(factory.createIdentifier('value')),
|
|
2495
|
+
],
|
|
2496
|
+
factory.createBlock(
|
|
2497
|
+
[
|
|
2498
|
+
factory.createExpressionStatement(
|
|
2499
|
+
factory.createAssignment(this.createAccess(nameComputed, name), factory.createIdentifier('value')),
|
|
2500
|
+
),
|
|
2501
|
+
],
|
|
2502
|
+
false,
|
|
2503
|
+
),
|
|
2504
|
+
),
|
|
2505
|
+
),
|
|
2506
|
+
);
|
|
2507
|
+
return factory.createObjectLiteral(
|
|
2508
|
+
[
|
|
2509
|
+
factory.createPropertyAssignment(
|
|
2510
|
+
factory.createIdentifier('kind'),
|
|
2511
|
+
factory.createStringLiteral(kind, TokenFlags.None),
|
|
2512
|
+
),
|
|
2513
|
+
factory.createPropertyAssignment(factory.createIdentifier('name'), nameValue),
|
|
2514
|
+
factory.createPropertyAssignment(
|
|
2515
|
+
factory.createIdentifier('static'),
|
|
2516
|
+
factory.createKeywordExpression(isStaticMember ? SyntaxKind.TrueKeyword : SyntaxKind.FalseKeyword),
|
|
2517
|
+
),
|
|
2518
|
+
factory.createPropertyAssignment(
|
|
2519
|
+
factory.createIdentifier('private'),
|
|
2520
|
+
factory.createKeywordExpression(isPrivate ? SyntaxKind.TrueKeyword : SyntaxKind.FalseKeyword),
|
|
2521
|
+
),
|
|
2522
|
+
factory.createPropertyAssignment(
|
|
2523
|
+
factory.createIdentifier('access'),
|
|
2524
|
+
factory.createObjectLiteral(access, false),
|
|
2525
|
+
),
|
|
2526
|
+
factory.createPropertyAssignment(factory.createIdentifier('metadata'), metadata),
|
|
2527
|
+
],
|
|
2528
|
+
false,
|
|
2529
|
+
);
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
private createAccess(nameComputed: boolean, name: Node): Node {
|
|
2533
|
+
const obj = this.factory.createIdentifier('obj');
|
|
2534
|
+
return nameComputed
|
|
2535
|
+
? this.factory.createElementAccessExpression(obj, name)
|
|
2536
|
+
: this.factory.createPropertyAccessExpression(obj, name);
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
/** `const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(superMetadata) : void 0;` */
|
|
2540
|
+
private createMetadata(name: Identifier, classSuper: Identifier | undefined): Node {
|
|
2541
|
+
const factory = this.factory;
|
|
2542
|
+
const superMetadata: Node =
|
|
2543
|
+
classSuper !== undefined
|
|
2544
|
+
? factory.createBinaryExpression(
|
|
2545
|
+
factory.createElementAccessExpression(classSuper, this.createSymbolMetadataAccess()),
|
|
2546
|
+
SyntaxKind.QuestionQuestionToken,
|
|
2547
|
+
factory.createToken(SyntaxKind.NullKeyword),
|
|
2548
|
+
)
|
|
2549
|
+
: factory.createToken(SyntaxKind.NullKeyword);
|
|
2550
|
+
const create = factory.createCallExpression(
|
|
2551
|
+
factory.createPropertyAccessExpression(factory.createIdentifier('Object'), factory.createIdentifier('create')),
|
|
2552
|
+
[superMetadata],
|
|
2553
|
+
);
|
|
2554
|
+
const symbolCheck = factory.createBinaryExpression(
|
|
2555
|
+
factory.createTypeCheck(factory.createIdentifier('Symbol'), 'function'),
|
|
2556
|
+
SyntaxKind.AmpersandAmpersandToken,
|
|
2557
|
+
this.createSymbolMetadataAccess(),
|
|
2558
|
+
);
|
|
2559
|
+
return factory.createVariableStatement(
|
|
2560
|
+
undefined,
|
|
2561
|
+
factory.createVariableDeclarationList(
|
|
2562
|
+
factory.createNodeList([
|
|
2563
|
+
factory.createVariableDeclaration(
|
|
2564
|
+
name,
|
|
2565
|
+
undefined,
|
|
2566
|
+
undefined,
|
|
2567
|
+
factory.createConditionalExpression(symbolCheck, create, factory.createVoidZero()),
|
|
2568
|
+
),
|
|
2569
|
+
]),
|
|
2570
|
+
NodeFlags.Const,
|
|
2571
|
+
),
|
|
2572
|
+
);
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2575
|
+
private createSymbolMetadataAccess(): Node {
|
|
2576
|
+
return this.factory.createPropertyAccessExpression(
|
|
2577
|
+
this.factory.createIdentifier('Symbol'),
|
|
2578
|
+
this.factory.createIdentifier('metadata'),
|
|
2579
|
+
);
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
/** `if (metadata) Object.defineProperty(target, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: metadata });` */
|
|
2583
|
+
private createSymbolMetadata(target: Node, value: Identifier): Node {
|
|
2584
|
+
const factory = this.factory;
|
|
2585
|
+
const descriptor = factory.createObjectLiteral(
|
|
2586
|
+
[
|
|
2587
|
+
factory.createPropertyAssignment(factory.createIdentifier('enumerable'), factory.createTrue()),
|
|
2588
|
+
factory.createPropertyAssignment(factory.createIdentifier('configurable'), factory.createTrue()),
|
|
2589
|
+
factory.createPropertyAssignment(factory.createIdentifier('writable'), factory.createTrue()),
|
|
2590
|
+
factory.createPropertyAssignment(factory.createIdentifier('value'), value),
|
|
2591
|
+
],
|
|
2592
|
+
false,
|
|
2593
|
+
);
|
|
2594
|
+
const defineProperty = factory.createCallExpression(
|
|
2595
|
+
factory.createPropertyAccessExpression(
|
|
2596
|
+
factory.createIdentifier('Object'),
|
|
2597
|
+
factory.createIdentifier('defineProperty'),
|
|
2598
|
+
),
|
|
2599
|
+
[target, this.createSymbolMetadataAccess(), descriptor],
|
|
2600
|
+
);
|
|
2601
|
+
const statement: IfStatement = factory.createIfStatement(
|
|
2602
|
+
value,
|
|
2603
|
+
factory.createExpressionStatement(defineProperty),
|
|
2604
|
+
undefined,
|
|
2605
|
+
);
|
|
2606
|
+
this.context.setEmitFlags(statement, EmitFlags.SingleLine);
|
|
2607
|
+
return statement;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
/** The callee and `this` argument of a call. */
|
|
2612
|
+
class CallBinding {
|
|
2613
|
+
readonly target: Node;
|
|
2614
|
+
readonly thisArg: Node;
|
|
2615
|
+
|
|
2616
|
+
constructor(target: Node, thisArg: Node) {
|
|
2617
|
+
this.target = target;
|
|
2618
|
+
this.thisArg = thisArg;
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
function shouldBeCapturedInTempVariable(node: Node): boolean {
|
|
2623
|
+
switch (skipParentheses(node).kind) {
|
|
2624
|
+
case SyntaxKind.ThisKeyword:
|
|
2625
|
+
case SyntaxKind.NumericLiteral:
|
|
2626
|
+
case SyntaxKind.BigIntLiteral:
|
|
2627
|
+
case SyntaxKind.StringLiteral:
|
|
2628
|
+
return false;
|
|
2629
|
+
}
|
|
2630
|
+
return true;
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
/** `_name`, `_get_name`, `_static_private_name`, `_class` or `_member`, for helper variables of `node`. */
|
|
2634
|
+
function getHelperVariableName(context: EmitContext, node: Node): string {
|
|
2635
|
+
const name = getName(node);
|
|
2636
|
+
let declarationName: string;
|
|
2637
|
+
if (name instanceof Identifier && !context.hasAutoGenerateInfo(name)) declarationName = name.text;
|
|
2638
|
+
else if (name instanceof PrivateIdentifier && !context.hasAutoGenerateInfo(name))
|
|
2639
|
+
declarationName = name.text.length > 1 ? name.text.slice(1) : '';
|
|
2640
|
+
else if (name instanceof StringLiteral && isIdentifierText(name.text)) declarationName = name.text;
|
|
2641
|
+
else if (isClassLike(node)) declarationName = 'class';
|
|
2642
|
+
else declarationName = 'member';
|
|
2643
|
+
if (node.kind === SyntaxKind.GetAccessor) declarationName = 'get_' + declarationName;
|
|
2644
|
+
if (node.kind === SyntaxKind.SetAccessor) declarationName = 'set_' + declarationName;
|
|
2645
|
+
if (name instanceof PrivateIdentifier) declarationName = 'private_' + declarationName;
|
|
2646
|
+
if (isStatic(node)) declarationName = 'static_' + declarationName;
|
|
2647
|
+
return '_' + declarationName;
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
function isStaticPrivateOrAutoAccessor(member: Node): boolean {
|
|
2651
|
+
return (
|
|
2652
|
+
(isPrivateIdentifierClassElementDeclaration(member) || isAutoAccessorPropertyDeclaration(member)) &&
|
|
2653
|
+
hasStaticModifier(member)
|
|
2654
|
+
);
|
|
2655
|
+
}
|
|
2656
|
+
|
|
2657
|
+
function keepsModifier(filter: ModifierFilter, kind: SyntaxKind): boolean {
|
|
2658
|
+
switch (filter) {
|
|
2659
|
+
case ModifierFilter.NoDecorators:
|
|
2660
|
+
return kind !== SyntaxKind.Decorator;
|
|
2661
|
+
case ModifierFilter.NoExport:
|
|
2662
|
+
return kind !== SyntaxKind.Decorator && kind !== SyntaxKind.ExportKeyword;
|
|
2663
|
+
case ModifierFilter.StaticOnly:
|
|
2664
|
+
return kind === SyntaxKind.StaticKeyword;
|
|
2665
|
+
case ModifierFilter.AsyncOnly:
|
|
2666
|
+
return kind === SyntaxKind.AsyncKeyword;
|
|
2667
|
+
case ModifierFilter.NoAccessor:
|
|
2668
|
+
return kind !== SyntaxKind.AccessorKeyword;
|
|
2669
|
+
}
|
|
2670
|
+
return true;
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
function pushVisited(statements: Node[], visited: Node | undefined): boolean {
|
|
2674
|
+
if (visited instanceof SyntaxList) appendAll(statements, visited.children);
|
|
2675
|
+
else if (visited !== undefined) statements.push(visited);
|
|
2676
|
+
return true;
|
|
2677
|
+
}
|
|
2678
|
+
|
|
2679
|
+
function appendAll(target: Node[], nodes: Node[]): boolean {
|
|
2680
|
+
for (let i = 0; i < nodes.length; i++) target.push(nodes[i]);
|
|
2681
|
+
return true;
|
|
2682
|
+
}
|