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,1901 @@
|
|
|
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 { ArrayLiteralExpression, BinaryExpression, BindingElement, Block, CallExpression, ClassDeclaration, ClassExpression, ClassStaticBlockDeclaration, ComputedPropertyName, ConstructorDeclaration, Decorator, ElementAccessExpression, ExportAssignment, ExpressionStatement, ExpressionWithTypeArguments, ForStatement, FunctionExpression, GetAccessorDeclaration, Identifier, MethodDeclaration, NodeList, ObjectLiteralExpression, ParameterDeclaration, ParenthesizedExpression, PartiallyEmittedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PrivateIdentifier, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, SetAccessorDeclaration, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SyntaxList, TaggedTemplateExpression, TryStatement, VariableDeclaration, getBody, getModifiers, getName, getParameters, } from '../ast.js';
|
|
10
|
+
import { isLeftHandSideExpression } from '../ast-utilities.js';
|
|
11
|
+
import { hasSyntacticModifier, hasStaticModifier, isAssignmentExpression, isAutoAccessorPropertyDeclaration, isClassLike, isDestructuringAssignment, isMethodOrAccessor, isPrivateIdentifierClassElementDeclaration, isPropertyNameLiteral, isStatic, skipParentheses, } from '../binder-utilities.js';
|
|
12
|
+
import { ScriptTarget, getEmitScriptTarget, getUseDefineForClassFields } from '../options.js';
|
|
13
|
+
import { createESDecorateHelper, createPropKeyHelper, createRunInitializersHelper, createSetFunctionNameHelper, } from '../printer/decorator-helpers.js';
|
|
14
|
+
import { isIdentifierText } from '../scanner.js';
|
|
15
|
+
import { countPrologueDirectives, createAccessorPropertyBackingField, createExportDefault, createExternalModuleExport, getClassHeritageClauses, getClassMembers, getClassName, expandPreOrPostfixIncrementOrDecrementExpression, findComputedPropertyNameCacheAssignment, findSuperStatementIndexPath, getHeritageClause, getNonAssignmentOperatorForCompoundAssignment, injectClassThisAssignmentIfMissing, isClassThisAssignmentBlock, isCompoundAssignment, isSuperProperty, } from './class-utilities.js';
|
|
16
|
+
import { childIsDecorated, classOrConstructorParameterIsDecorated, getDecorators, getFirstConstructorWithBody, isSimpleInlineableExpression, moveRangePastDecorators, moveRangePastModifiers, nodeIsDecorated, nodeOrChildIsDecorated, } from './decorator-utilities.js';
|
|
17
|
+
import { AnonymousFunctionFilter, classHasDeclaredOrExplicitlyAssignedName, injectClassNamedEvaluationHelperBlockIfMissing, isClassNamedEvaluationHelperBlock, isNamedEvaluation, transformNamedEvaluation, } from './named-evaluation.js';
|
|
18
|
+
import { Transformer } from './transformer.js';
|
|
19
|
+
import { hasDecorators, singleOrMany, skipOuterExpressions } from './utilities.js';
|
|
20
|
+
import { VisitorBase } from './visitor-base.js';
|
|
21
|
+
/** An entry of the stack of classes, class elements, names and other scopes being visited. */
|
|
22
|
+
class LexicalEntry {
|
|
23
|
+
kind;
|
|
24
|
+
next;
|
|
25
|
+
classInfo;
|
|
26
|
+
savedPendingExpressions;
|
|
27
|
+
classThis;
|
|
28
|
+
classSuper;
|
|
29
|
+
depth;
|
|
30
|
+
constructor(kind, next, classInfo, savedPendingExpressions) {
|
|
31
|
+
this.kind = kind;
|
|
32
|
+
this.next = next;
|
|
33
|
+
this.classInfo = classInfo;
|
|
34
|
+
this.savedPendingExpressions = savedPendingExpressions;
|
|
35
|
+
this.classThis = undefined;
|
|
36
|
+
this.classSuper = undefined;
|
|
37
|
+
this.depth = 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** The helper variables of one decorated class element. */
|
|
41
|
+
class MemberInfo {
|
|
42
|
+
decoratorsName;
|
|
43
|
+
initializersName;
|
|
44
|
+
extraInitializersName;
|
|
45
|
+
descriptorName;
|
|
46
|
+
constructor(decoratorsName) {
|
|
47
|
+
this.decoratorsName = decoratorsName;
|
|
48
|
+
this.initializersName = undefined;
|
|
49
|
+
this.extraInitializersName = undefined;
|
|
50
|
+
this.descriptorName = undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** What transforming one decorated class collects. */
|
|
54
|
+
class ClassInfo {
|
|
55
|
+
metadataReference;
|
|
56
|
+
classDecoratorsName;
|
|
57
|
+
classDescriptorName;
|
|
58
|
+
classExtraInitializersName;
|
|
59
|
+
classThis;
|
|
60
|
+
classSuper;
|
|
61
|
+
/** Decorated members, in order, and their helper variables. */
|
|
62
|
+
decoratedMembers;
|
|
63
|
+
memberInfos;
|
|
64
|
+
instanceMethodExtraInitializersName;
|
|
65
|
+
staticMethodExtraInitializersName;
|
|
66
|
+
staticNonFieldDecorationStatements;
|
|
67
|
+
nonStaticNonFieldDecorationStatements;
|
|
68
|
+
staticFieldDecorationStatements;
|
|
69
|
+
nonStaticFieldDecorationStatements;
|
|
70
|
+
hasStaticInitializers;
|
|
71
|
+
hasNonAmbientInstanceFields;
|
|
72
|
+
hasStaticPrivateClassElements;
|
|
73
|
+
pendingStaticInitializers;
|
|
74
|
+
pendingInstanceInitializers;
|
|
75
|
+
constructor(metadataReference) {
|
|
76
|
+
this.metadataReference = metadataReference;
|
|
77
|
+
this.classDecoratorsName = undefined;
|
|
78
|
+
this.classDescriptorName = undefined;
|
|
79
|
+
this.classExtraInitializersName = undefined;
|
|
80
|
+
this.classThis = undefined;
|
|
81
|
+
this.classSuper = undefined;
|
|
82
|
+
this.decoratedMembers = [];
|
|
83
|
+
this.memberInfos = [];
|
|
84
|
+
this.instanceMethodExtraInitializersName = undefined;
|
|
85
|
+
this.staticMethodExtraInitializersName = undefined;
|
|
86
|
+
this.staticNonFieldDecorationStatements = [];
|
|
87
|
+
this.nonStaticNonFieldDecorationStatements = [];
|
|
88
|
+
this.staticFieldDecorationStatements = [];
|
|
89
|
+
this.nonStaticFieldDecorationStatements = [];
|
|
90
|
+
this.hasStaticInitializers = false;
|
|
91
|
+
this.hasNonAmbientInstanceFields = false;
|
|
92
|
+
this.hasStaticPrivateClassElements = false;
|
|
93
|
+
this.pendingStaticInitializers = [];
|
|
94
|
+
this.pendingInstanceInitializers = [];
|
|
95
|
+
}
|
|
96
|
+
setMemberInfo(member, info) {
|
|
97
|
+
const index = this.decoratedMembers.indexOf(member);
|
|
98
|
+
if (index >= 0)
|
|
99
|
+
this.memberInfos[index] = info;
|
|
100
|
+
else {
|
|
101
|
+
this.decoratedMembers.push(member);
|
|
102
|
+
this.memberInfos.push(info);
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/** The result of the shared part of transforming a class element. */
|
|
108
|
+
class PartialResult {
|
|
109
|
+
modifiers;
|
|
110
|
+
referencedName;
|
|
111
|
+
name;
|
|
112
|
+
initializersName;
|
|
113
|
+
extraInitializersName;
|
|
114
|
+
descriptorName;
|
|
115
|
+
thisArg;
|
|
116
|
+
constructor(modifiers) {
|
|
117
|
+
this.modifiers = modifiers;
|
|
118
|
+
this.referencedName = undefined;
|
|
119
|
+
this.name = undefined;
|
|
120
|
+
this.initializersName = undefined;
|
|
121
|
+
this.extraInitializersName = undefined;
|
|
122
|
+
this.descriptorName = undefined;
|
|
123
|
+
this.thisArg = undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Anonymous decorated class expressions, which need an assigned name. */
|
|
127
|
+
class AnonymousDecoratedClassFilter extends AnonymousFunctionFilter {
|
|
128
|
+
accepts(node) {
|
|
129
|
+
return node instanceof ClassExpression && node.name === undefined && isDecoratedClassLike(node);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const anonymousDecoratedClass = new AnonymousDecoratedClassFilter();
|
|
133
|
+
function isDecoratedClassLike(node) {
|
|
134
|
+
return classOrConstructorParameterIsDecorated(false, node) || childIsDecorated(false, node, undefined);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* The IIFE for `(@dec class {})` assigns `var class_1 = class {}`, so an empty assigned name
|
|
138
|
+
* matters; the one for `(class { @dec x; })` returns the class directly, so it can be ignored.
|
|
139
|
+
*/
|
|
140
|
+
function canIgnoreEmptyStringLiteralInAssignedName(node) {
|
|
141
|
+
if (node === undefined)
|
|
142
|
+
return false;
|
|
143
|
+
const inner = skipOuterExpressions(node, 63 /* OuterExpressionKinds.All */);
|
|
144
|
+
return (inner instanceof ClassExpression &&
|
|
145
|
+
inner.name === undefined &&
|
|
146
|
+
!classOrConstructorParameterIsDecorated(false, inner));
|
|
147
|
+
}
|
|
148
|
+
/** Replaces lexical `this` with `_outerThis`, for expressions moved into a class `static {}` block. */
|
|
149
|
+
class OuterThisVisitor extends VisitorBase {
|
|
150
|
+
owner;
|
|
151
|
+
constructor(owner) {
|
|
152
|
+
super(owner.context);
|
|
153
|
+
this.owner = owner;
|
|
154
|
+
}
|
|
155
|
+
visit(node) {
|
|
156
|
+
return this.owner.visitOuterThis(node, this);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/** Whether ES decorators need lowering for these options. */
|
|
160
|
+
export function shouldTransformESDecorators(options) {
|
|
161
|
+
if (options.experimentalDecorators === true)
|
|
162
|
+
return false;
|
|
163
|
+
return getEmitScriptTarget(options) < ScriptTarget.ESNext || !getUseDefineForClassFields(options);
|
|
164
|
+
}
|
|
165
|
+
export class ESDecorators extends Transformer {
|
|
166
|
+
facts;
|
|
167
|
+
outerThisVisitor;
|
|
168
|
+
top;
|
|
169
|
+
classInfo;
|
|
170
|
+
classThis;
|
|
171
|
+
classSuper;
|
|
172
|
+
pendingExpressions;
|
|
173
|
+
outerThis;
|
|
174
|
+
shouldTransformPrivateStaticElementsInFile;
|
|
175
|
+
constructor(context, facts) {
|
|
176
|
+
super(context);
|
|
177
|
+
this.facts = facts;
|
|
178
|
+
this.outerThisVisitor = new OuterThisVisitor(this);
|
|
179
|
+
this.top = undefined;
|
|
180
|
+
this.classInfo = undefined;
|
|
181
|
+
this.classThis = undefined;
|
|
182
|
+
this.classSuper = undefined;
|
|
183
|
+
this.pendingExpressions = [];
|
|
184
|
+
this.outerThis = undefined;
|
|
185
|
+
this.shouldTransformPrivateStaticElementsInFile = false;
|
|
186
|
+
}
|
|
187
|
+
// Lexical state
|
|
188
|
+
updateState() {
|
|
189
|
+
this.classInfo = undefined;
|
|
190
|
+
this.classThis = undefined;
|
|
191
|
+
this.classSuper = undefined;
|
|
192
|
+
const top = this.top;
|
|
193
|
+
if (top === undefined)
|
|
194
|
+
return false;
|
|
195
|
+
switch (top.kind) {
|
|
196
|
+
case 0 /* LexicalEntryKind.Class */:
|
|
197
|
+
this.classInfo = top.classInfo;
|
|
198
|
+
break;
|
|
199
|
+
case 1 /* LexicalEntryKind.ClassElement */:
|
|
200
|
+
this.classInfo = top.next.classInfo;
|
|
201
|
+
this.classThis = top.classThis;
|
|
202
|
+
this.classSuper = top.classSuper;
|
|
203
|
+
break;
|
|
204
|
+
case 2 /* LexicalEntryKind.Name */: {
|
|
205
|
+
const grandparent = top.next.next.next;
|
|
206
|
+
if (grandparent !== undefined && grandparent.kind === 1 /* LexicalEntryKind.ClassElement */) {
|
|
207
|
+
this.classInfo = grandparent.next.classInfo;
|
|
208
|
+
this.classThis = grandparent.classThis;
|
|
209
|
+
this.classSuper = grandparent.classSuper;
|
|
210
|
+
}
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
enterClass(info) {
|
|
217
|
+
this.top = new LexicalEntry(0 /* LexicalEntryKind.Class */, this.top, info, this.pendingExpressions);
|
|
218
|
+
this.pendingExpressions = [];
|
|
219
|
+
return this.updateState();
|
|
220
|
+
}
|
|
221
|
+
exitClass() {
|
|
222
|
+
const top = this.top;
|
|
223
|
+
this.pendingExpressions = top.savedPendingExpressions;
|
|
224
|
+
this.top = top.next;
|
|
225
|
+
return this.updateState();
|
|
226
|
+
}
|
|
227
|
+
enterClassElement(node) {
|
|
228
|
+
const entry = new LexicalEntry(1 /* LexicalEntryKind.ClassElement */, this.top, undefined, undefined);
|
|
229
|
+
this.top = entry;
|
|
230
|
+
if (node.kind === 176 /* SyntaxKind.ClassStaticBlockDeclaration */ ||
|
|
231
|
+
(node.kind === 173 /* SyntaxKind.PropertyDeclaration */ && hasStaticModifier(node))) {
|
|
232
|
+
const info = entry.next.classInfo;
|
|
233
|
+
if (info !== undefined) {
|
|
234
|
+
entry.classThis = info.classThis;
|
|
235
|
+
entry.classSuper = info.classSuper;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return this.updateState();
|
|
239
|
+
}
|
|
240
|
+
exitClassElement() {
|
|
241
|
+
this.top = this.top.next;
|
|
242
|
+
return this.updateState();
|
|
243
|
+
}
|
|
244
|
+
enterName() {
|
|
245
|
+
this.top = new LexicalEntry(2 /* LexicalEntryKind.Name */, this.top, undefined, undefined);
|
|
246
|
+
return this.updateState();
|
|
247
|
+
}
|
|
248
|
+
exitName() {
|
|
249
|
+
this.top = this.top.next;
|
|
250
|
+
return this.updateState();
|
|
251
|
+
}
|
|
252
|
+
enterOther() {
|
|
253
|
+
const top = this.top;
|
|
254
|
+
if (top !== undefined && top.kind === 3 /* LexicalEntryKind.Other */) {
|
|
255
|
+
top.depth++;
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
this.top = new LexicalEntry(3 /* LexicalEntryKind.Other */, top, undefined, this.pendingExpressions);
|
|
259
|
+
this.pendingExpressions = [];
|
|
260
|
+
return this.updateState();
|
|
261
|
+
}
|
|
262
|
+
exitOther() {
|
|
263
|
+
const top = this.top;
|
|
264
|
+
if (top.depth > 0) {
|
|
265
|
+
top.depth--;
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
this.pendingExpressions = top.savedPendingExpressions;
|
|
269
|
+
this.top = top.next;
|
|
270
|
+
return this.updateState();
|
|
271
|
+
}
|
|
272
|
+
// Visitors
|
|
273
|
+
shouldVisitNode(node) {
|
|
274
|
+
const facts = this.facts.of(node);
|
|
275
|
+
return ((facts & 262144 /* SubtreeFacts.ContainsDecorators */) !== 0 ||
|
|
276
|
+
(this.classThis !== undefined && (facts & 2048 /* SubtreeFacts.ContainsLexicalThis */) !== 0) ||
|
|
277
|
+
(this.classThis !== undefined &&
|
|
278
|
+
this.classSuper !== undefined &&
|
|
279
|
+
(facts & 4096 /* SubtreeFacts.ContainsLexicalSuper */) !== 0));
|
|
280
|
+
}
|
|
281
|
+
visit(node) {
|
|
282
|
+
if (node instanceof SourceFile)
|
|
283
|
+
return this.visitSourceFile(node);
|
|
284
|
+
if (!this.shouldVisitNode(node))
|
|
285
|
+
return node;
|
|
286
|
+
switch (node.kind) {
|
|
287
|
+
case 171 /* SyntaxKind.Decorator */:
|
|
288
|
+
return undefined;
|
|
289
|
+
case 264 /* SyntaxKind.ClassDeclaration */:
|
|
290
|
+
if (node instanceof ClassDeclaration)
|
|
291
|
+
return this.visitClassDeclaration(node);
|
|
292
|
+
break;
|
|
293
|
+
case 232 /* SyntaxKind.ClassExpression */:
|
|
294
|
+
if (node instanceof ClassExpression)
|
|
295
|
+
return this.visitClassExpression(node);
|
|
296
|
+
break;
|
|
297
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
298
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
299
|
+
case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
|
|
300
|
+
throw new Error('Class elements are visited with visitClassElement');
|
|
301
|
+
case 170 /* SyntaxKind.Parameter */:
|
|
302
|
+
if (node instanceof ParameterDeclaration)
|
|
303
|
+
return this.visitParameterDeclaration(node);
|
|
304
|
+
break;
|
|
305
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
306
|
+
if (node instanceof BinaryExpression)
|
|
307
|
+
return this.visitBinaryExpression(node, false);
|
|
308
|
+
break;
|
|
309
|
+
case 303 /* SyntaxKind.PropertyAssignment */:
|
|
310
|
+
if (node instanceof PropertyAssignment)
|
|
311
|
+
return this.visitNamedEvaluationSite(node, node.initializer);
|
|
312
|
+
break;
|
|
313
|
+
case 261 /* SyntaxKind.VariableDeclaration */:
|
|
314
|
+
if (node instanceof VariableDeclaration)
|
|
315
|
+
return this.visitNamedEvaluationSite(node, node.initializer);
|
|
316
|
+
break;
|
|
317
|
+
case 209 /* SyntaxKind.BindingElement */:
|
|
318
|
+
if (node instanceof BindingElement)
|
|
319
|
+
return this.visitNamedEvaluationSite(node, node.initializer);
|
|
320
|
+
break;
|
|
321
|
+
case 278 /* SyntaxKind.ExportAssignment */:
|
|
322
|
+
if (node instanceof ExportAssignment)
|
|
323
|
+
return this.visitNamedEvaluationSite(node, node.expression);
|
|
324
|
+
break;
|
|
325
|
+
case 109 /* SyntaxKind.ThisKeyword */:
|
|
326
|
+
return this.classThis !== undefined ? this.classThis : node;
|
|
327
|
+
case 249 /* SyntaxKind.ForStatement */:
|
|
328
|
+
if (node instanceof ForStatement)
|
|
329
|
+
return this.visitForStatement(node);
|
|
330
|
+
break;
|
|
331
|
+
case 245 /* SyntaxKind.ExpressionStatement */:
|
|
332
|
+
if (node instanceof ExpressionStatement)
|
|
333
|
+
return this.factory.updateExpressionStatement(node, this.visitDiscardedNode(node.expression));
|
|
334
|
+
break;
|
|
335
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
336
|
+
if (node instanceof ParenthesizedExpression)
|
|
337
|
+
return this.visitParenthesizedExpression(node, false);
|
|
338
|
+
break;
|
|
339
|
+
case 348 /* SyntaxKind.PartiallyEmittedExpression */:
|
|
340
|
+
if (node instanceof PartiallyEmittedExpression)
|
|
341
|
+
return this.visitPartiallyEmittedExpression(node, false);
|
|
342
|
+
break;
|
|
343
|
+
case 214 /* SyntaxKind.CallExpression */:
|
|
344
|
+
if (node instanceof CallExpression)
|
|
345
|
+
return this.visitCallExpression(node);
|
|
346
|
+
break;
|
|
347
|
+
case 216 /* SyntaxKind.TaggedTemplateExpression */:
|
|
348
|
+
if (node instanceof TaggedTemplateExpression)
|
|
349
|
+
return this.visitTaggedTemplateExpression(node);
|
|
350
|
+
break;
|
|
351
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */:
|
|
352
|
+
case 226 /* SyntaxKind.PostfixUnaryExpression */:
|
|
353
|
+
return this.visitPreOrPostfixUnaryExpression(node, false);
|
|
354
|
+
case 212 /* SyntaxKind.PropertyAccessExpression */:
|
|
355
|
+
if (node instanceof PropertyAccessExpression)
|
|
356
|
+
return this.visitPropertyAccessExpression(node);
|
|
357
|
+
break;
|
|
358
|
+
case 213 /* SyntaxKind.ElementAccessExpression */:
|
|
359
|
+
if (node instanceof ElementAccessExpression)
|
|
360
|
+
return this.visitElementAccessExpression(node);
|
|
361
|
+
break;
|
|
362
|
+
case 168 /* SyntaxKind.ComputedPropertyName */:
|
|
363
|
+
if (node instanceof ComputedPropertyName)
|
|
364
|
+
return this.visitComputedPropertyName(node);
|
|
365
|
+
break;
|
|
366
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
367
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
368
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
369
|
+
case 219 /* SyntaxKind.FunctionExpression */:
|
|
370
|
+
case 263 /* SyntaxKind.FunctionDeclaration */: {
|
|
371
|
+
this.enterOther();
|
|
372
|
+
const result = this.visitEachChild(node);
|
|
373
|
+
this.exitOther();
|
|
374
|
+
return result;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
return this.visitEachChild(node);
|
|
378
|
+
}
|
|
379
|
+
visitSourceFile(node) {
|
|
380
|
+
this.top = undefined;
|
|
381
|
+
this.shouldTransformPrivateStaticElementsInFile = false;
|
|
382
|
+
const visited = this.visitEachChild(node);
|
|
383
|
+
const helpers = this.context.readEmitHelpers();
|
|
384
|
+
for (let i = 0; i < helpers.length; i++)
|
|
385
|
+
this.context.addEmitHelper(visited, helpers[i]);
|
|
386
|
+
if (this.shouldTransformPrivateStaticElementsInFile) {
|
|
387
|
+
this.context.addEmitFlags(visited, 8388608 /* EmitFlags.TransformPrivateStaticElements */);
|
|
388
|
+
this.shouldTransformPrivateStaticElementsInFile = false;
|
|
389
|
+
}
|
|
390
|
+
return visited;
|
|
391
|
+
}
|
|
392
|
+
/** `this` as `_outerThis`, for the outer-this visitor. */
|
|
393
|
+
visitOuterThis(node, visitor) {
|
|
394
|
+
if (node.kind === 109 /* SyntaxKind.ThisKeyword */) {
|
|
395
|
+
if (this.outerThis === undefined)
|
|
396
|
+
this.outerThis = this.factory.createUniqueName('_outerThis', 16 /* GeneratedIdentifierFlags.Optimistic */);
|
|
397
|
+
return this.outerThis;
|
|
398
|
+
}
|
|
399
|
+
if (!this.facts.has(node, 2048 /* SubtreeFacts.ContainsLexicalThis */))
|
|
400
|
+
return node;
|
|
401
|
+
return visitor.visitEachChild(node);
|
|
402
|
+
}
|
|
403
|
+
visitClassElement(node) {
|
|
404
|
+
switch (node.kind) {
|
|
405
|
+
case 177 /* SyntaxKind.Constructor */:
|
|
406
|
+
if (node instanceof ConstructorDeclaration)
|
|
407
|
+
return this.visitConstructorDeclaration(node);
|
|
408
|
+
break;
|
|
409
|
+
case 175 /* SyntaxKind.MethodDeclaration */:
|
|
410
|
+
if (node instanceof MethodDeclaration)
|
|
411
|
+
return this.visitMethodDeclaration(node);
|
|
412
|
+
break;
|
|
413
|
+
case 178 /* SyntaxKind.GetAccessor */:
|
|
414
|
+
if (node instanceof GetAccessorDeclaration)
|
|
415
|
+
return this.visitGetAccessorDeclaration(node);
|
|
416
|
+
break;
|
|
417
|
+
case 179 /* SyntaxKind.SetAccessor */:
|
|
418
|
+
if (node instanceof SetAccessorDeclaration)
|
|
419
|
+
return this.visitSetAccessorDeclaration(node);
|
|
420
|
+
break;
|
|
421
|
+
case 173 /* SyntaxKind.PropertyDeclaration */:
|
|
422
|
+
if (node instanceof PropertyDeclaration)
|
|
423
|
+
return this.visitPropertyDeclaration(node);
|
|
424
|
+
break;
|
|
425
|
+
case 176 /* SyntaxKind.ClassStaticBlockDeclaration */:
|
|
426
|
+
if (node instanceof ClassStaticBlockDeclaration)
|
|
427
|
+
return this.visitClassStaticBlockDeclaration(node);
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
return this.visit(node);
|
|
431
|
+
}
|
|
432
|
+
/** Visits a node whose value is discarded, such as an expression statement's expression. */
|
|
433
|
+
visitDiscarded(node) {
|
|
434
|
+
switch (node.kind) {
|
|
435
|
+
case 225 /* SyntaxKind.PrefixUnaryExpression */:
|
|
436
|
+
case 226 /* SyntaxKind.PostfixUnaryExpression */:
|
|
437
|
+
return this.visitPreOrPostfixUnaryExpression(node, true);
|
|
438
|
+
case 227 /* SyntaxKind.BinaryExpression */:
|
|
439
|
+
if (node instanceof BinaryExpression)
|
|
440
|
+
return this.visitBinaryExpression(node, true);
|
|
441
|
+
break;
|
|
442
|
+
case 218 /* SyntaxKind.ParenthesizedExpression */:
|
|
443
|
+
if (node instanceof ParenthesizedExpression)
|
|
444
|
+
return this.visitParenthesizedExpression(node, true);
|
|
445
|
+
break;
|
|
446
|
+
case 348 /* SyntaxKind.PartiallyEmittedExpression */:
|
|
447
|
+
if (node instanceof PartiallyEmittedExpression)
|
|
448
|
+
return this.visitPartiallyEmittedExpression(node, true);
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
return this.visit(node);
|
|
452
|
+
}
|
|
453
|
+
visitDiscardedNode(node) {
|
|
454
|
+
return node === undefined ? undefined : this.visitDiscarded(node);
|
|
455
|
+
}
|
|
456
|
+
visitListItem(node, mode) {
|
|
457
|
+
switch (mode) {
|
|
458
|
+
case 0 /* ListVisit.ClassElements */:
|
|
459
|
+
return this.visitClassElement(node);
|
|
460
|
+
case 1 /* ListVisit.NonConstructorClassElements */:
|
|
461
|
+
return node.kind === 177 /* SyntaxKind.Constructor */ ? node : this.visitClassElement(node);
|
|
462
|
+
case 2 /* ListVisit.ConstructorClassElements */:
|
|
463
|
+
return node.kind === 177 /* SyntaxKind.Constructor */ ? this.visitClassElement(node) : node;
|
|
464
|
+
case 3 /* ListVisit.ArrayAssignmentElements */:
|
|
465
|
+
return this.visitArrayAssignmentElement(node);
|
|
466
|
+
case 4 /* ListVisit.ObjectAssignmentElements */:
|
|
467
|
+
return this.visitObjectAssignmentElement(node);
|
|
468
|
+
}
|
|
469
|
+
return node;
|
|
470
|
+
}
|
|
471
|
+
/** Visits each node of a list with the visitor `mode` names; the list itself if nothing changed. */
|
|
472
|
+
visitList(list, mode) {
|
|
473
|
+
const nodes = list.nodes;
|
|
474
|
+
let updated = undefined;
|
|
475
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
476
|
+
const visited = this.visitListItem(nodes[i], mode);
|
|
477
|
+
if (updated === undefined) {
|
|
478
|
+
if (visited === nodes[i])
|
|
479
|
+
continue;
|
|
480
|
+
updated = nodes.slice(0, i);
|
|
481
|
+
}
|
|
482
|
+
if (visited instanceof SyntaxList)
|
|
483
|
+
for (let j = 0; j < visited.children.length; j++)
|
|
484
|
+
updated.push(visited.children[j]);
|
|
485
|
+
else if (visited !== undefined)
|
|
486
|
+
updated.push(visited);
|
|
487
|
+
}
|
|
488
|
+
return updated === undefined ? list : new NodeList(list.pos, list.end, updated);
|
|
489
|
+
}
|
|
490
|
+
filterModifiers(list, filter) {
|
|
491
|
+
if (list === undefined)
|
|
492
|
+
return undefined;
|
|
493
|
+
const nodes = list.nodes;
|
|
494
|
+
let kept = undefined;
|
|
495
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
496
|
+
const keep = keepsModifier(filter, nodes[i].kind);
|
|
497
|
+
if (keep && kept !== undefined)
|
|
498
|
+
kept.push(nodes[i]);
|
|
499
|
+
else if (!keep && kept === undefined)
|
|
500
|
+
kept = nodes.slice(0, i);
|
|
501
|
+
}
|
|
502
|
+
if (kept === undefined)
|
|
503
|
+
return list;
|
|
504
|
+
const updated = this.factory.createModifierList(kept);
|
|
505
|
+
updated.pos = list.pos;
|
|
506
|
+
updated.end = list.end;
|
|
507
|
+
return updated;
|
|
508
|
+
}
|
|
509
|
+
// Classes
|
|
510
|
+
createHelperVariable(node, suffix) {
|
|
511
|
+
return this.factory.createUniqueName(getHelperVariableName(this.context, node) + '_' + suffix, 16 /* GeneratedIdentifierFlags.Optimistic */ | 8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */);
|
|
512
|
+
}
|
|
513
|
+
createFileLevelName(text) {
|
|
514
|
+
return this.factory.createUniqueName(text, 16 /* GeneratedIdentifierFlags.Optimistic */ | 32 /* GeneratedIdentifierFlags.FileLevel */);
|
|
515
|
+
}
|
|
516
|
+
createLet(name, initializer) {
|
|
517
|
+
const factory = this.factory;
|
|
518
|
+
return factory.createVariableStatement(undefined, factory.createVariableDeclarationList(factory.createNodeList([factory.createVariableDeclaration(name, undefined, undefined, initializer)]), 1 /* NodeFlags.Let */));
|
|
519
|
+
}
|
|
520
|
+
createEmptyArray() {
|
|
521
|
+
return this.factory.created(new ArrayLiteralExpression(this.factory.createNodeList([]), false));
|
|
522
|
+
}
|
|
523
|
+
setRangePastDecoratorsOrName(initializer, node) {
|
|
524
|
+
const name = getClassName(node);
|
|
525
|
+
if (name !== undefined)
|
|
526
|
+
this.context.setSourceMapRange(initializer, name.pos, name.end);
|
|
527
|
+
else
|
|
528
|
+
this.context.setSourceMapRange(initializer, moveRangePastDecorators(node).pos, node.end);
|
|
529
|
+
return true;
|
|
530
|
+
}
|
|
531
|
+
createClassInfo(node) {
|
|
532
|
+
const factory = this.factory;
|
|
533
|
+
const info = new ClassInfo(this.createFileLevelName('_metadata'));
|
|
534
|
+
const members = getClassMembers(node).nodes;
|
|
535
|
+
if (nodeIsDecorated(false, node, undefined, undefined)) {
|
|
536
|
+
let needsUniqueClassThis = false;
|
|
537
|
+
for (let i = 0; i < members.length; i++)
|
|
538
|
+
if (isStaticPrivateOrAutoAccessor(members[i])) {
|
|
539
|
+
needsUniqueClassThis = true;
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
// `_classThis` isn't file level when class private fields may need an outer class's.
|
|
543
|
+
info.classThis = factory.createUniqueName('_classThis', needsUniqueClassThis
|
|
544
|
+
? 16 /* GeneratedIdentifierFlags.Optimistic */ | 8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */
|
|
545
|
+
: 16 /* GeneratedIdentifierFlags.Optimistic */ | 32 /* GeneratedIdentifierFlags.FileLevel */);
|
|
546
|
+
}
|
|
547
|
+
for (let i = 0; i < members.length; i++) {
|
|
548
|
+
const member = members[i];
|
|
549
|
+
if (isMethodOrAccessor(member) && nodeOrChildIsDecorated(false, member, node, undefined)) {
|
|
550
|
+
if (hasStaticModifier(member)) {
|
|
551
|
+
if (info.staticMethodExtraInitializersName === undefined) {
|
|
552
|
+
info.staticMethodExtraInitializersName = this.createFileLevelName('_staticExtraInitializers');
|
|
553
|
+
const initializer = createRunInitializersHelper(factory, info.classThis !== undefined ? info.classThis : factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), info.staticMethodExtraInitializersName, undefined);
|
|
554
|
+
this.setRangePastDecoratorsOrName(initializer, node);
|
|
555
|
+
info.pendingStaticInitializers.push(initializer);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
else if (info.instanceMethodExtraInitializersName === undefined) {
|
|
559
|
+
info.instanceMethodExtraInitializersName = this.createFileLevelName('_instanceExtraInitializers');
|
|
560
|
+
const initializer = createRunInitializersHelper(factory, factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), info.instanceMethodExtraInitializersName, undefined);
|
|
561
|
+
this.setRangePastDecoratorsOrName(initializer, node);
|
|
562
|
+
info.pendingInstanceInitializers.push(initializer);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (member instanceof ClassStaticBlockDeclaration) {
|
|
566
|
+
if (!isClassNamedEvaluationHelperBlock(this.context, member))
|
|
567
|
+
info.hasStaticInitializers = true;
|
|
568
|
+
}
|
|
569
|
+
else if (member instanceof PropertyDeclaration) {
|
|
570
|
+
if (hasStaticModifier(member))
|
|
571
|
+
info.hasStaticInitializers =
|
|
572
|
+
info.hasStaticInitializers || member.initializer !== undefined || hasDecorators(member);
|
|
573
|
+
else
|
|
574
|
+
info.hasNonAmbientInstanceFields =
|
|
575
|
+
info.hasNonAmbientInstanceFields || !hasSyntacticModifier(member, 128 /* ModifierFlags.Ambient */);
|
|
576
|
+
}
|
|
577
|
+
if (isStaticPrivateOrAutoAccessor(member))
|
|
578
|
+
info.hasStaticPrivateClassElements = true;
|
|
579
|
+
if (info.staticMethodExtraInitializersName !== undefined &&
|
|
580
|
+
info.instanceMethodExtraInitializersName !== undefined &&
|
|
581
|
+
info.hasStaticInitializers &&
|
|
582
|
+
info.hasNonAmbientInstanceFields &&
|
|
583
|
+
info.hasStaticPrivateClassElements)
|
|
584
|
+
break;
|
|
585
|
+
}
|
|
586
|
+
return info;
|
|
587
|
+
}
|
|
588
|
+
transformClassLike(original) {
|
|
589
|
+
const factory = this.factory;
|
|
590
|
+
const context = this.context;
|
|
591
|
+
context.startVariableEnvironment();
|
|
592
|
+
let node = original;
|
|
593
|
+
// A class that gets class decorators is moved into a statement that would give it an
|
|
594
|
+
// assigned name; without one, it gets the assigned name `""`.
|
|
595
|
+
if (!classHasDeclaredOrExplicitlyAssignedName(context, node) && classOrConstructorParameterIsDecorated(false, node))
|
|
596
|
+
node = injectClassNamedEvaluationHelperBlockIfMissing(context, node, factory.createStringLiteral('', 0 /* TokenFlags.None */), undefined);
|
|
597
|
+
const cls = node;
|
|
598
|
+
const classMembers = getClassMembers(cls);
|
|
599
|
+
const classReference = factory.getLocalName(cls, 0 /* NameOptions.None */);
|
|
600
|
+
const info = this.createClassInfo(cls);
|
|
601
|
+
const classDefinitionStatements = [];
|
|
602
|
+
let leadingBlockStatements = [];
|
|
603
|
+
let trailingBlockStatements = [];
|
|
604
|
+
let syntheticConstructor = undefined;
|
|
605
|
+
let heritageClauses = undefined;
|
|
606
|
+
let shouldTransformPrivateStaticElementsInClass = false;
|
|
607
|
+
// 1. Class decorators are evaluated outside the private name scope of the class.
|
|
608
|
+
const classDecorators = this.transformAllDecoratorsOfDeclaration(getDecorators(cls));
|
|
609
|
+
if (classDecorators.length > 0) {
|
|
610
|
+
info.classDecoratorsName = this.createFileLevelName('_classDecorators');
|
|
611
|
+
info.classDescriptorName = this.createFileLevelName('_classDescriptor');
|
|
612
|
+
info.classExtraInitializersName = this.createFileLevelName('_classExtraInitializers');
|
|
613
|
+
classDefinitionStatements.push(this.createLet(info.classDecoratorsName, factory.created(new ArrayLiteralExpression(factory.createNodeList(classDecorators), false))), this.createLet(info.classDescriptorName, undefined), this.createLet(info.classExtraInitializersName, this.createEmptyArray()), this.createLet(info.classThis, undefined));
|
|
614
|
+
if (info.hasStaticPrivateClassElements) {
|
|
615
|
+
shouldTransformPrivateStaticElementsInClass = true;
|
|
616
|
+
this.shouldTransformPrivateStaticElementsInFile = true;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
// 2. The heritage clause is evaluated outside the private name scope of the class.
|
|
620
|
+
const extendsClause = getHeritageClause(getClassHeritageClauses(cls), 95 /* SyntaxKind.ExtendsKeyword */);
|
|
621
|
+
let extendsElement = undefined;
|
|
622
|
+
if (extendsClause !== undefined && extendsClause.types.nodes.length > 0) {
|
|
623
|
+
const first = extendsClause.types.nodes[0];
|
|
624
|
+
if (first instanceof ExpressionWithTypeArguments)
|
|
625
|
+
extendsElement = first;
|
|
626
|
+
}
|
|
627
|
+
const extendsExpression = extendsElement !== undefined ? this.visitNode(extendsElement.expression) : undefined;
|
|
628
|
+
const heritageElement = extendsElement;
|
|
629
|
+
if (extendsClause !== undefined && heritageElement !== undefined && extendsExpression !== undefined) {
|
|
630
|
+
// `super` in static initializers is rewritten to use `_classSuper` with the right `this`.
|
|
631
|
+
info.classSuper = this.createFileLevelName('_classSuper');
|
|
632
|
+
// `0, ` keeps the variable from assigning a name to an anonymous class or function.
|
|
633
|
+
const unwrapped = skipOuterExpressions(extendsExpression, 63 /* OuterExpressionKinds.All */);
|
|
634
|
+
const anonymous = (unwrapped instanceof ClassExpression && unwrapped.name === undefined) ||
|
|
635
|
+
(unwrapped instanceof FunctionExpression && unwrapped.name === undefined) ||
|
|
636
|
+
unwrapped.kind === 220 /* SyntaxKind.ArrowFunction */;
|
|
637
|
+
const safeExtendsExpression = anonymous
|
|
638
|
+
? factory.createCommaExpression(factory.createNumericLiteral('0'), extendsExpression)
|
|
639
|
+
: extendsExpression;
|
|
640
|
+
classDefinitionStatements.push(this.createLet(info.classSuper, safeExtendsExpression));
|
|
641
|
+
const updatedElement = factory.updateExpressionWithTypeArguments(heritageElement, info.classSuper, undefined);
|
|
642
|
+
const updatedClause = factory.updateHeritageClause(extendsClause, extendsClause.token, factory.createNodeList([updatedElement]));
|
|
643
|
+
heritageClauses = factory.createNodeList([updatedClause]);
|
|
644
|
+
}
|
|
645
|
+
const renamedClassThis = info.classThis !== undefined ? info.classThis : factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */);
|
|
646
|
+
// 3. The name of the class is assigned (by the named evaluation block, if needed).
|
|
647
|
+
// 4. For each member, its decorators and then its computed name are evaluated. Members
|
|
648
|
+
// other than the constructor are visited first, since its transform depends on them.
|
|
649
|
+
this.enterClass(info);
|
|
650
|
+
leadingBlockStatements.push(this.createMetadata(info.metadataReference, info.classSuper));
|
|
651
|
+
let members = this.visitList(classMembers, 1 /* ListVisit.NonConstructorClassElements */);
|
|
652
|
+
members = this.visitList(members, 2 /* ListVisit.ConstructorClassElements */);
|
|
653
|
+
if (this.pendingExpressions.length > 0) {
|
|
654
|
+
// Lexical `this` in a pending expression is the container's, captured in `_outerThis`.
|
|
655
|
+
this.outerThis = undefined;
|
|
656
|
+
for (let i = 0; i < this.pendingExpressions.length; i++) {
|
|
657
|
+
let expression = this.pendingExpressions[i];
|
|
658
|
+
if (this.facts.has(expression, 2048 /* SubtreeFacts.ContainsLexicalThis */))
|
|
659
|
+
expression = this.outerThisVisitor.visitNode(expression);
|
|
660
|
+
leadingBlockStatements.push(factory.createExpressionStatement(expression));
|
|
661
|
+
}
|
|
662
|
+
if (this.outerThis !== undefined)
|
|
663
|
+
classDefinitionStatements.unshift(this.createLet(this.outerThis, factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */)));
|
|
664
|
+
this.pendingExpressions = [];
|
|
665
|
+
}
|
|
666
|
+
this.exitClass();
|
|
667
|
+
if (info.pendingInstanceInitializers.length > 0 && getFirstConstructorWithBody(cls) === undefined) {
|
|
668
|
+
const initializerStatements = this.prepareConstructor(info);
|
|
669
|
+
if (initializerStatements.length > 0) {
|
|
670
|
+
const heritage = extendsElement;
|
|
671
|
+
const isDerivedClass = heritage !== undefined &&
|
|
672
|
+
skipOuterExpressions(heritage.expression, 63 /* OuterExpressionKinds.All */).kind !== 105 /* SyntaxKind.NullKeyword */;
|
|
673
|
+
const constructorStatements = [];
|
|
674
|
+
if (isDerivedClass)
|
|
675
|
+
constructorStatements.push(factory.createExpressionStatement(factory.createCallExpression(factory.createKeywordExpression(107 /* SyntaxKind.SuperKeyword */), [
|
|
676
|
+
factory.created(new SpreadElement(factory.createIdentifier('arguments'))),
|
|
677
|
+
])));
|
|
678
|
+
for (let i = 0; i < initializerStatements.length; i++)
|
|
679
|
+
constructorStatements.push(initializerStatements[i]);
|
|
680
|
+
syntheticConstructor = factory.created(new ConstructorDeclaration(undefined, undefined, factory.createNodeList([]), undefined, undefined, factory.createBlock(constructorStatements, true)));
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (info.staticMethodExtraInitializersName !== undefined)
|
|
684
|
+
classDefinitionStatements.push(this.createLet(info.staticMethodExtraInitializersName, this.createEmptyArray()));
|
|
685
|
+
if (info.instanceMethodExtraInitializersName !== undefined)
|
|
686
|
+
classDefinitionStatements.push(this.createLet(info.instanceMethodExtraInitializersName, this.createEmptyArray()));
|
|
687
|
+
if (info.memberInfos.length > 0) {
|
|
688
|
+
// Static members' variables come first.
|
|
689
|
+
this.addMemberInfoDeclarations(classDefinitionStatements, info, true);
|
|
690
|
+
this.addMemberInfoDeclarations(classDefinitionStatements, info, false);
|
|
691
|
+
}
|
|
692
|
+
// 5-8. Member decorators are applied.
|
|
693
|
+
appendAll(leadingBlockStatements, info.staticNonFieldDecorationStatements);
|
|
694
|
+
appendAll(leadingBlockStatements, info.nonStaticNonFieldDecorationStatements);
|
|
695
|
+
appendAll(leadingBlockStatements, info.staticFieldDecorationStatements);
|
|
696
|
+
appendAll(leadingBlockStatements, info.nonStaticFieldDecorationStatements);
|
|
697
|
+
// 9. Class decorators are applied, and 10. the class binding is initialized:
|
|
698
|
+
// __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata }, null, _classExtraInitializers);
|
|
699
|
+
// C = _classThis = _classDescriptor.value;
|
|
700
|
+
if (info.classDescriptorName !== undefined &&
|
|
701
|
+
info.classDecoratorsName !== undefined &&
|
|
702
|
+
info.classExtraInitializersName !== undefined &&
|
|
703
|
+
info.classThis !== undefined) {
|
|
704
|
+
const classDescriptor = factory.createObjectLiteral([factory.createPropertyAssignment(factory.createIdentifier('value'), renamedClassThis)], false);
|
|
705
|
+
const contextObject = factory.createObjectLiteral([
|
|
706
|
+
factory.createPropertyAssignment(factory.createIdentifier('kind'), factory.createStringLiteral('class', 0 /* TokenFlags.None */)),
|
|
707
|
+
factory.createPropertyAssignment(factory.createIdentifier('name'), factory.createPropertyAccessExpression(renamedClassThis, factory.createIdentifier('name'))),
|
|
708
|
+
factory.createPropertyAssignment(factory.createIdentifier('metadata'), info.metadataReference),
|
|
709
|
+
], false);
|
|
710
|
+
const decorate = factory.createExpressionStatement(createESDecorateHelper(factory, factory.createToken(105 /* SyntaxKind.NullKeyword */), factory.createAssignment(info.classDescriptorName, classDescriptor), info.classDecoratorsName, contextObject, factory.createToken(105 /* SyntaxKind.NullKeyword */), info.classExtraInitializersName));
|
|
711
|
+
context.setSourceMapRange(decorate, moveRangePastDecorators(cls).pos, cls.end);
|
|
712
|
+
leadingBlockStatements.push(decorate);
|
|
713
|
+
leadingBlockStatements.push(factory.createExpressionStatement(factory.createAssignment(classReference, factory.createAssignment(info.classThis, factory.createPropertyAccessExpression(info.classDescriptorName, factory.createIdentifier('value'))))));
|
|
714
|
+
}
|
|
715
|
+
// if (_metadata) Object.defineProperty(C, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
716
|
+
leadingBlockStatements.push(this.createSymbolMetadata(renamedClassThis, info.metadataReference));
|
|
717
|
+
// 11. Static extra initializers and 12. static fields are run.
|
|
718
|
+
for (let i = 0; i < info.pendingStaticInitializers.length; i++) {
|
|
719
|
+
const initializer = info.pendingStaticInitializers[i];
|
|
720
|
+
const statement = factory.createExpressionStatement(initializer);
|
|
721
|
+
context.setSourceMapRange(statement, context.sourceMapPos(initializer), context.sourceMapEnd(initializer));
|
|
722
|
+
trailingBlockStatements.push(statement);
|
|
723
|
+
}
|
|
724
|
+
info.pendingStaticInitializers = [];
|
|
725
|
+
// 13. Class extra initializers are run.
|
|
726
|
+
if (info.classExtraInitializersName !== undefined) {
|
|
727
|
+
const statement = factory.createExpressionStatement(createRunInitializersHelper(factory, renamedClassThis, info.classExtraInitializersName, undefined));
|
|
728
|
+
this.setRangePastDecoratorsOrName(statement, cls);
|
|
729
|
+
trailingBlockStatements.push(statement);
|
|
730
|
+
}
|
|
731
|
+
// Without other static initializers, the leading and trailing blocks are one.
|
|
732
|
+
if (leadingBlockStatements.length > 0 && trailingBlockStatements.length > 0 && !info.hasStaticInitializers) {
|
|
733
|
+
appendAll(leadingBlockStatements, trailingBlockStatements);
|
|
734
|
+
trailingBlockStatements = [];
|
|
735
|
+
}
|
|
736
|
+
let leadingStaticBlock = undefined;
|
|
737
|
+
if (leadingBlockStatements.length > 0)
|
|
738
|
+
leadingStaticBlock = factory.created(new ClassStaticBlockDeclaration(undefined, factory.createBlock(leadingBlockStatements, true)));
|
|
739
|
+
// Tells the class fields transform not to rename `this` to `_classThis` in this block.
|
|
740
|
+
if (leadingStaticBlock !== undefined && shouldTransformPrivateStaticElementsInClass)
|
|
741
|
+
context.setEmitFlags(leadingStaticBlock, 8388608 /* EmitFlags.TransformPrivateStaticElements */);
|
|
742
|
+
let trailingStaticBlock = undefined;
|
|
743
|
+
if (trailingBlockStatements.length > 0)
|
|
744
|
+
trailingStaticBlock = factory.created(new ClassStaticBlockDeclaration(undefined, factory.createBlock(trailingBlockStatements, true)));
|
|
745
|
+
leadingBlockStatements = [];
|
|
746
|
+
if (leadingStaticBlock !== undefined || syntheticConstructor !== undefined || trailingStaticBlock !== undefined) {
|
|
747
|
+
const existing = members.nodes;
|
|
748
|
+
let helperBlockIndex = -1;
|
|
749
|
+
for (let i = 0; i < existing.length; i++)
|
|
750
|
+
if (isClassNamedEvaluationHelperBlock(context, existing[i])) {
|
|
751
|
+
helperBlockIndex = i;
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
754
|
+
const updated = [];
|
|
755
|
+
if (leadingStaticBlock !== undefined) {
|
|
756
|
+
// After the named evaluation block, if there is one.
|
|
757
|
+
for (let i = 0; i <= helperBlockIndex; i++)
|
|
758
|
+
updated.push(existing[i]);
|
|
759
|
+
updated.push(leadingStaticBlock);
|
|
760
|
+
for (let i = helperBlockIndex + 1; i < existing.length; i++)
|
|
761
|
+
updated.push(existing[i]);
|
|
762
|
+
}
|
|
763
|
+
else
|
|
764
|
+
appendAll(updated, existing);
|
|
765
|
+
if (syntheticConstructor !== undefined)
|
|
766
|
+
updated.push(syntheticConstructor);
|
|
767
|
+
if (trailingStaticBlock !== undefined)
|
|
768
|
+
updated.push(trailingStaticBlock);
|
|
769
|
+
members = new NodeList(members.pos, members.end, updated);
|
|
770
|
+
}
|
|
771
|
+
const lexicalEnvironment = context.endVariableEnvironment();
|
|
772
|
+
let classExpression;
|
|
773
|
+
if (classDecorators.length > 0) {
|
|
774
|
+
// `var` uses NamedEvaluation to name the class and is initialized before any `static {}` use:
|
|
775
|
+
// (() => { let _classDecorators = [...]; ...; var C = class { static { ... } }; return C = _classThis; })();
|
|
776
|
+
classExpression = factory.created(new ClassExpression(undefined, undefined, undefined, heritageClauses, members));
|
|
777
|
+
context.setOriginal(classExpression, cls);
|
|
778
|
+
if (info.classThis !== undefined)
|
|
779
|
+
classExpression = injectClassThisAssignmentIfMissing(context, classExpression, info.classThis);
|
|
780
|
+
classDefinitionStatements.push(factory.createVariableStatement(undefined, factory.createVariableDeclarationList(factory.createNodeList([
|
|
781
|
+
factory.createVariableDeclaration(classReference, undefined, undefined, classExpression),
|
|
782
|
+
]), 0 /* NodeFlags.None */)), factory.createReturnStatement(info.classThis !== undefined ? factory.createAssignment(classReference, info.classThis) : classReference));
|
|
783
|
+
}
|
|
784
|
+
else {
|
|
785
|
+
// return <classExpression>;
|
|
786
|
+
classExpression = factory.created(new ClassExpression(undefined, getClassName(cls), undefined, heritageClauses, members));
|
|
787
|
+
context.setOriginal(classExpression, cls);
|
|
788
|
+
classDefinitionStatements.push(factory.createReturnStatement(classExpression));
|
|
789
|
+
}
|
|
790
|
+
if (shouldTransformPrivateStaticElementsInClass && classExpression instanceof ClassExpression) {
|
|
791
|
+
context.addEmitFlags(classExpression, 8388608 /* EmitFlags.TransformPrivateStaticElements */);
|
|
792
|
+
const classMembers = classExpression.members.nodes;
|
|
793
|
+
for (let i = 0; i < classMembers.length; i++)
|
|
794
|
+
if (isStaticPrivateOrAutoAccessor(classMembers[i]))
|
|
795
|
+
context.addEmitFlags(classMembers[i], 8388608 /* EmitFlags.TransformPrivateStaticElements */);
|
|
796
|
+
}
|
|
797
|
+
return factory.createImmediatelyInvokedArrowFunction(context.mergeEnvironment(classDefinitionStatements, lexicalEnvironment));
|
|
798
|
+
}
|
|
799
|
+
addMemberInfoDeclarations(statements, info, isStaticMember) {
|
|
800
|
+
for (let i = 0; i < info.memberInfos.length; i++) {
|
|
801
|
+
if (isStatic(info.decoratedMembers[i]) !== isStaticMember)
|
|
802
|
+
continue;
|
|
803
|
+
const memberInfo = info.memberInfos[i];
|
|
804
|
+
statements.push(this.createLet(memberInfo.decoratorsName, undefined));
|
|
805
|
+
if (memberInfo.initializersName !== undefined)
|
|
806
|
+
statements.push(this.createLet(memberInfo.initializersName, this.createEmptyArray()));
|
|
807
|
+
if (memberInfo.extraInitializersName !== undefined)
|
|
808
|
+
statements.push(this.createLet(memberInfo.extraInitializersName, this.createEmptyArray()));
|
|
809
|
+
if (memberInfo.descriptorName !== undefined)
|
|
810
|
+
statements.push(this.createLet(memberInfo.descriptorName, undefined));
|
|
811
|
+
}
|
|
812
|
+
return true;
|
|
813
|
+
}
|
|
814
|
+
visitClassDeclaration(node) {
|
|
815
|
+
const factory = this.factory;
|
|
816
|
+
const context = this.context;
|
|
817
|
+
if (!isDecoratedClassLike(node)) {
|
|
818
|
+
const modifiers = this.filterModifiers(node.modifiers, 0 /* ModifierFilter.NoDecorators */);
|
|
819
|
+
const heritageClauses = this.visitNodes(node.heritageClauses);
|
|
820
|
+
this.enterClass(undefined);
|
|
821
|
+
const members = this.visitList(node.members, 0 /* ListVisit.ClassElements */);
|
|
822
|
+
this.exitClass();
|
|
823
|
+
return factory.updateClassDeclaration(node, modifiers, node.name, undefined, heritageClauses, members);
|
|
824
|
+
}
|
|
825
|
+
const statements = [];
|
|
826
|
+
let originalClass = context.mostOriginal(node);
|
|
827
|
+
if (!isClassLike(originalClass))
|
|
828
|
+
originalClass = node;
|
|
829
|
+
const originalName = getName(originalClass);
|
|
830
|
+
const className = originalName !== undefined
|
|
831
|
+
? factory.createStringLiteralFromNode(originalName)
|
|
832
|
+
: factory.createStringLiteral('default', 0 /* TokenFlags.None */);
|
|
833
|
+
const isExport = hasSyntacticModifier(node, 32 /* ModifierFlags.Export */);
|
|
834
|
+
const isDefault = hasSyntacticModifier(node, 2048 /* ModifierFlags.Default */);
|
|
835
|
+
let classNode = node;
|
|
836
|
+
if (node.name === undefined)
|
|
837
|
+
classNode = injectClassNamedEvaluationHelperBlockIfMissing(context, node, className, undefined);
|
|
838
|
+
if (isExport && isDefault) {
|
|
839
|
+
const iife = this.transformClassLike(classNode);
|
|
840
|
+
if (classNode.name !== undefined) {
|
|
841
|
+
// let C = (() => { ... })();
|
|
842
|
+
// export default C;
|
|
843
|
+
const declaration = factory.createVariableDeclaration(factory.getLocalName(classNode, 0 /* NameOptions.None */), undefined, undefined, iife);
|
|
844
|
+
context.setOriginal(declaration, classNode);
|
|
845
|
+
statements.push(factory.createVariableStatement(undefined, factory.createVariableDeclarationList(factory.createNodeList([declaration]), 1 /* NodeFlags.Let */)));
|
|
846
|
+
const exportStatement = createExportDefault(factory, factory.getDeclarationName(classNode, 0 /* NameOptions.None */));
|
|
847
|
+
context.setOriginal(exportStatement, classNode);
|
|
848
|
+
context.assignCommentRange(exportStatement, classNode);
|
|
849
|
+
context.setSourceMapRange(exportStatement, moveRangePastDecorators(classNode).pos, classNode.end);
|
|
850
|
+
statements.push(exportStatement);
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
// export default (() => { ... })();
|
|
854
|
+
const exportStatement = createExportDefault(factory, iife);
|
|
855
|
+
context.setOriginal(exportStatement, classNode);
|
|
856
|
+
context.assignCommentRange(exportStatement, classNode);
|
|
857
|
+
context.setSourceMapRange(exportStatement, moveRangePastDecorators(classNode).pos, classNode.end);
|
|
858
|
+
statements.push(exportStatement);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
else {
|
|
862
|
+
// let C = (() => { ... })();
|
|
863
|
+
const iife = this.transformClassLike(classNode);
|
|
864
|
+
const modifiers = this.filterModifiers(classNode.modifiers, 1 /* ModifierFilter.NoExport */);
|
|
865
|
+
const declarationName = factory.getLocalName(classNode, 2 /* NameOptions.AllowSourceMaps */);
|
|
866
|
+
const declaration = factory.createVariableDeclaration(declarationName, undefined, undefined, iife);
|
|
867
|
+
context.setOriginal(declaration, classNode);
|
|
868
|
+
const statement = factory.createVariableStatement(modifiers, factory.createVariableDeclarationList(factory.createNodeList([declaration]), 1 /* NodeFlags.Let */));
|
|
869
|
+
context.setOriginal(statement, classNode);
|
|
870
|
+
context.assignCommentRange(statement, classNode);
|
|
871
|
+
statements.push(statement);
|
|
872
|
+
if (isExport) {
|
|
873
|
+
// export { C };
|
|
874
|
+
const exportStatement = createExternalModuleExport(factory, declarationName);
|
|
875
|
+
context.setOriginal(exportStatement, classNode);
|
|
876
|
+
statements.push(exportStatement);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return singleOrMany(statements, factory);
|
|
880
|
+
}
|
|
881
|
+
visitClassExpression(node) {
|
|
882
|
+
if (isDecoratedClassLike(node)) {
|
|
883
|
+
const iife = this.transformClassLike(node);
|
|
884
|
+
this.context.setOriginal(iife, node);
|
|
885
|
+
return iife;
|
|
886
|
+
}
|
|
887
|
+
const modifiers = this.filterModifiers(node.modifiers, 0 /* ModifierFilter.NoDecorators */);
|
|
888
|
+
const heritageClauses = this.visitNodes(node.heritageClauses);
|
|
889
|
+
this.enterClass(undefined);
|
|
890
|
+
const members = this.visitList(node.members, 0 /* ListVisit.ClassElements */);
|
|
891
|
+
this.exitClass();
|
|
892
|
+
return this.factory.updateClassExpression(node, modifiers, node.name, undefined, heritageClauses, members);
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* The `__runInitializers()` call for instance extra initializers, when no instance field
|
|
896
|
+
* initializer carries it.
|
|
897
|
+
*/
|
|
898
|
+
prepareConstructor(info) {
|
|
899
|
+
if (info.pendingInstanceInitializers.length === 0)
|
|
900
|
+
return [];
|
|
901
|
+
const statements = [
|
|
902
|
+
this.factory.createExpressionStatement(this.factory.inlineExpressions(info.pendingInstanceInitializers)),
|
|
903
|
+
];
|
|
904
|
+
info.pendingInstanceInitializers = [];
|
|
905
|
+
return statements;
|
|
906
|
+
}
|
|
907
|
+
/** Visits constructor statements, adding the initializers after the `super()` call `superPath` leads to. */
|
|
908
|
+
transformConstructorBody(statementsOut, statementsIn, statementOffset, superPath, superPathDepth, initializerStatements) {
|
|
909
|
+
const superStatementIndex = superPath[superPathDepth];
|
|
910
|
+
for (let i = statementOffset; i < superStatementIndex; i++)
|
|
911
|
+
pushVisited(statementsOut, this.visitNode(statementsIn[i]));
|
|
912
|
+
const superStatement = statementsIn[superStatementIndex];
|
|
913
|
+
if (superStatement instanceof TryStatement) {
|
|
914
|
+
const tryStatement = superStatement;
|
|
915
|
+
const tryBlock = tryStatement.tryBlock;
|
|
916
|
+
const tryStatements = this.transformConstructorBody([], tryBlock.statements.nodes, 0, superPath, superPathDepth + 1, initializerStatements);
|
|
917
|
+
// Keeps the original try block's range for source maps.
|
|
918
|
+
const newTryBlock = this.factory.createBlock(tryStatements, true);
|
|
919
|
+
newTryBlock.pos = tryBlock.pos;
|
|
920
|
+
newTryBlock.end = tryBlock.end;
|
|
921
|
+
let catchClause = undefined;
|
|
922
|
+
if (tryStatement.catchClause !== undefined)
|
|
923
|
+
catchClause = this.visitNode(tryStatement.catchClause);
|
|
924
|
+
let finallyBlock = undefined;
|
|
925
|
+
if (tryStatement.finallyBlock !== undefined)
|
|
926
|
+
finallyBlock = this.visitNode(tryStatement.finallyBlock);
|
|
927
|
+
const updated = this.factory.updateTryStatement(tryStatement, newTryBlock, catchClause, finallyBlock);
|
|
928
|
+
statementsOut.push(updated);
|
|
929
|
+
}
|
|
930
|
+
else {
|
|
931
|
+
pushVisited(statementsOut, this.visitNode(superStatement));
|
|
932
|
+
appendAll(statementsOut, initializerStatements);
|
|
933
|
+
}
|
|
934
|
+
for (let i = superStatementIndex + 1; i < statementsIn.length; i++)
|
|
935
|
+
pushVisited(statementsOut, this.visitNode(statementsIn[i]));
|
|
936
|
+
return statementsOut;
|
|
937
|
+
}
|
|
938
|
+
visitConstructorDeclaration(node) {
|
|
939
|
+
this.enterClassElement(node);
|
|
940
|
+
const modifiers = this.filterModifiers(node.modifiers, 0 /* ModifierFilter.NoDecorators */);
|
|
941
|
+
const parameters = this.visitNodes(node.parameters);
|
|
942
|
+
let body = undefined;
|
|
943
|
+
const originalBody = node.body;
|
|
944
|
+
if (originalBody instanceof Block && this.classInfo !== undefined) {
|
|
945
|
+
// Instance extra initializers go into the body.
|
|
946
|
+
const initializerStatements = this.prepareConstructor(this.classInfo);
|
|
947
|
+
if (initializerStatements.length > 0) {
|
|
948
|
+
const statements = [];
|
|
949
|
+
const all = originalBody.statements.nodes;
|
|
950
|
+
const prologueCount = countPrologueDirectives(all);
|
|
951
|
+
for (let i = 0; i < prologueCount; i++)
|
|
952
|
+
statements.push(all[i]);
|
|
953
|
+
const rest = all.slice(prologueCount);
|
|
954
|
+
const superPath = findSuperStatementIndexPath(rest, 0);
|
|
955
|
+
if (superPath.length > 0)
|
|
956
|
+
this.transformConstructorBody(statements, rest, 0, superPath, 0, initializerStatements);
|
|
957
|
+
else {
|
|
958
|
+
appendAll(statements, initializerStatements);
|
|
959
|
+
appendAll(statements, this.visitArray(rest));
|
|
960
|
+
}
|
|
961
|
+
body = this.factory.createBlock(statements, true);
|
|
962
|
+
this.context.setOriginal(body, originalBody);
|
|
963
|
+
body.pos = originalBody.pos;
|
|
964
|
+
body.end = originalBody.end;
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
if (body === undefined)
|
|
968
|
+
body = this.visitNode(originalBody);
|
|
969
|
+
this.exitClassElement();
|
|
970
|
+
return this.factory.updateConstructorDeclaration(node, modifiers, undefined, parameters, undefined, undefined, body);
|
|
971
|
+
}
|
|
972
|
+
finishClassElement(updated, original) {
|
|
973
|
+
if (updated !== original) {
|
|
974
|
+
// Source maps start past decorators and modifiers, but comments cover the original range.
|
|
975
|
+
this.context.assignCommentRange(updated, original);
|
|
976
|
+
this.context.setSourceMapRange(updated, moveRangePastDecorators(original).pos, original.end);
|
|
977
|
+
}
|
|
978
|
+
return updated;
|
|
979
|
+
}
|
|
980
|
+
partialTransformClassElement(member, info, descriptorKind) {
|
|
981
|
+
const factory = this.factory;
|
|
982
|
+
const context = this.context;
|
|
983
|
+
const memberName = getName(member);
|
|
984
|
+
if (info === undefined) {
|
|
985
|
+
const result = new PartialResult(this.filterModifiers(getModifiers(member), 0 /* ModifierFilter.NoDecorators */));
|
|
986
|
+
this.enterName();
|
|
987
|
+
result.name = this.visitPropertyName(memberName);
|
|
988
|
+
this.exitName();
|
|
989
|
+
return result;
|
|
990
|
+
}
|
|
991
|
+
// Member decorators have privileged access to private names, but computed names are
|
|
992
|
+
// evaluated interspersed with them, so decorator evaluation is inlined into the names.
|
|
993
|
+
// Decorators are evaluated outside the class body, so `this` isn't `_classThis` there.
|
|
994
|
+
const savedClassThis = this.classThis;
|
|
995
|
+
this.classThis = undefined;
|
|
996
|
+
const memberDecorators = this.transformAllDecoratorsOfDeclaration(getDecorators(member));
|
|
997
|
+
this.classThis = savedClassThis;
|
|
998
|
+
const modifiers = this.filterModifiers(getModifiers(member), 0 /* ModifierFilter.NoDecorators */);
|
|
999
|
+
const result = new PartialResult(modifiers);
|
|
1000
|
+
if (memberDecorators.length > 0) {
|
|
1001
|
+
const memberDecoratorsName = this.createHelperVariable(member, 'decorators');
|
|
1002
|
+
const memberInfo = new MemberInfo(memberDecoratorsName);
|
|
1003
|
+
info.setMemberInfo(member, memberInfo);
|
|
1004
|
+
this.pendingExpressions.push(factory.createAssignment(memberDecoratorsName, factory.created(new ArrayLiteralExpression(factory.createNodeList(memberDecorators), false))));
|
|
1005
|
+
const kind = member.kind === 178 /* SyntaxKind.GetAccessor */
|
|
1006
|
+
? 'getter'
|
|
1007
|
+
: member.kind === 179 /* SyntaxKind.SetAccessor */
|
|
1008
|
+
? 'setter'
|
|
1009
|
+
: member.kind === 175 /* SyntaxKind.MethodDeclaration */
|
|
1010
|
+
? 'method'
|
|
1011
|
+
: isAutoAccessorPropertyDeclaration(member)
|
|
1012
|
+
? 'accessor'
|
|
1013
|
+
: 'field';
|
|
1014
|
+
let nameComputed = false;
|
|
1015
|
+
let nameExpression = undefined;
|
|
1016
|
+
if (memberName instanceof Identifier || memberName instanceof PrivateIdentifier)
|
|
1017
|
+
nameExpression = memberName;
|
|
1018
|
+
else if (memberName !== undefined && isPropertyNameLiteral(memberName)) {
|
|
1019
|
+
nameComputed = true;
|
|
1020
|
+
nameExpression = factory.createStringLiteralFromNode(memberName);
|
|
1021
|
+
}
|
|
1022
|
+
else if (memberName instanceof ComputedPropertyName) {
|
|
1023
|
+
const expression = memberName.expression;
|
|
1024
|
+
nameComputed = true;
|
|
1025
|
+
if (isPropertyNameLiteral(expression) && !(expression instanceof Identifier))
|
|
1026
|
+
nameExpression = factory.createStringLiteralFromNode(expression);
|
|
1027
|
+
else {
|
|
1028
|
+
this.enterName();
|
|
1029
|
+
this.visitReferencedPropertyName(memberName, result);
|
|
1030
|
+
this.exitName();
|
|
1031
|
+
nameExpression = result.referencedName;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
const isField = member.kind === 173 /* SyntaxKind.PropertyDeclaration */;
|
|
1035
|
+
const contextObject = this.createClassElementContextObject(kind, nameComputed, nameExpression, isStatic(member), memberName instanceof PrivateIdentifier, isField || member.kind === 178 /* SyntaxKind.GetAccessor */ || member.kind === 175 /* SyntaxKind.MethodDeclaration */, isField || member.kind === 179 /* SyntaxKind.SetAccessor */, info.metadataReference);
|
|
1036
|
+
if (isMethodOrAccessor(member)) {
|
|
1037
|
+
// __esDecorate(this, null | _member_descriptor = { value() { ... } }, _member_decorators, { kind: "method", ... }, null, _instanceExtraInitializers);
|
|
1038
|
+
const extraInitializersName = isStatic(member)
|
|
1039
|
+
? info.staticMethodExtraInitializersName
|
|
1040
|
+
: info.instanceMethodExtraInitializersName;
|
|
1041
|
+
let descriptor;
|
|
1042
|
+
if (isPrivateIdentifierClassElementDeclaration(member) && descriptorKind !== 0 /* DescriptorKind.None */) {
|
|
1043
|
+
// A private member's body moves into a descriptor object, keeping only `async`.
|
|
1044
|
+
const descriptorObject = this.createDescriptorObject(descriptorKind, member, this.filterModifiers(modifiers, 3 /* ModifierFilter.AsyncOnly */));
|
|
1045
|
+
memberInfo.descriptorName = this.createHelperVariable(member, 'descriptor');
|
|
1046
|
+
result.descriptorName = memberInfo.descriptorName;
|
|
1047
|
+
descriptor = factory.createAssignment(memberInfo.descriptorName, descriptorObject);
|
|
1048
|
+
}
|
|
1049
|
+
else
|
|
1050
|
+
descriptor = factory.createToken(105 /* SyntaxKind.NullKeyword */);
|
|
1051
|
+
const statement = factory.createExpressionStatement(createESDecorateHelper(factory, factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), descriptor, memberDecoratorsName, contextObject, factory.createToken(105 /* SyntaxKind.NullKeyword */), extraInitializersName));
|
|
1052
|
+
context.setSourceMapRange(statement, moveRangePastDecorators(member).pos, member.end);
|
|
1053
|
+
this.appendDecorationStatement(info, member, statement);
|
|
1054
|
+
}
|
|
1055
|
+
else if (isField) {
|
|
1056
|
+
// __esDecorate(null | this, null | _member_descriptor = { get() { ... }, set(value) { ... } }, _member_decorators, { kind: "field", ... }, _member_initializers, _member_extraInitializers);
|
|
1057
|
+
memberInfo.initializersName = this.createHelperVariable(member, 'initializers');
|
|
1058
|
+
memberInfo.extraInitializersName = this.createHelperVariable(member, 'extraInitializers');
|
|
1059
|
+
result.initializersName = memberInfo.initializersName;
|
|
1060
|
+
result.extraInitializersName = memberInfo.extraInitializersName;
|
|
1061
|
+
if (isStatic(member))
|
|
1062
|
+
result.thisArg = info.classThis;
|
|
1063
|
+
const ctor = isAutoAccessorPropertyDeclaration(member)
|
|
1064
|
+
? factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */)
|
|
1065
|
+
: factory.createToken(105 /* SyntaxKind.NullKeyword */);
|
|
1066
|
+
let descriptor;
|
|
1067
|
+
if (isPrivateIdentifierClassElementDeclaration(member) &&
|
|
1068
|
+
hasSyntacticModifier(member, 512 /* ModifierFlags.Accessor */) &&
|
|
1069
|
+
descriptorKind !== 0 /* DescriptorKind.None */) {
|
|
1070
|
+
const descriptorObject = this.createDescriptorObject(descriptorKind, member, undefined);
|
|
1071
|
+
memberInfo.descriptorName = this.createHelperVariable(member, 'descriptor');
|
|
1072
|
+
result.descriptorName = memberInfo.descriptorName;
|
|
1073
|
+
descriptor = factory.createAssignment(memberInfo.descriptorName, descriptorObject);
|
|
1074
|
+
}
|
|
1075
|
+
else
|
|
1076
|
+
descriptor = factory.createToken(105 /* SyntaxKind.NullKeyword */);
|
|
1077
|
+
const statement = factory.createExpressionStatement(createESDecorateHelper(factory, ctor, descriptor, memberDecoratorsName, contextObject, memberInfo.initializersName, memberInfo.extraInitializersName));
|
|
1078
|
+
context.setSourceMapRange(statement, moveRangePastDecorators(member).pos, member.end);
|
|
1079
|
+
this.appendDecorationStatement(info, member, statement);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
if (result.name === undefined) {
|
|
1083
|
+
this.enterName();
|
|
1084
|
+
result.name = this.visitPropertyName(memberName);
|
|
1085
|
+
this.exitName();
|
|
1086
|
+
}
|
|
1087
|
+
// Comments of methods and properties without modifiers would print twice on the name.
|
|
1088
|
+
if ((modifiers === undefined || modifiers.nodes.length === 0) &&
|
|
1089
|
+
(member.kind === 175 /* SyntaxKind.MethodDeclaration */ || member.kind === 173 /* SyntaxKind.PropertyDeclaration */))
|
|
1090
|
+
context.setEmitFlags(result.name, 128 /* EmitFlags.NoLeadingComments */);
|
|
1091
|
+
return result;
|
|
1092
|
+
}
|
|
1093
|
+
appendDecorationStatement(info, member, statement) {
|
|
1094
|
+
if (isMethodOrAccessor(member) || isAutoAccessorPropertyDeclaration(member)) {
|
|
1095
|
+
if (isStatic(member))
|
|
1096
|
+
info.staticNonFieldDecorationStatements.push(statement);
|
|
1097
|
+
else
|
|
1098
|
+
info.nonStaticNonFieldDecorationStatements.push(statement);
|
|
1099
|
+
}
|
|
1100
|
+
else if (isStatic(member))
|
|
1101
|
+
info.staticFieldDecorationStatements.push(statement);
|
|
1102
|
+
else
|
|
1103
|
+
info.nonStaticFieldDecorationStatements.push(statement);
|
|
1104
|
+
return true;
|
|
1105
|
+
}
|
|
1106
|
+
// Class elements
|
|
1107
|
+
visitMethodDeclaration(node) {
|
|
1108
|
+
this.enterClassElement(node);
|
|
1109
|
+
const result = this.partialTransformClassElement(node, this.classInfo, 1 /* DescriptorKind.Method */);
|
|
1110
|
+
if (result.descriptorName !== undefined) {
|
|
1111
|
+
this.exitClassElement();
|
|
1112
|
+
return this.finishClassElement(this.createMethodDescriptorForwarder(result.modifiers, result.name, result.descriptorName), node);
|
|
1113
|
+
}
|
|
1114
|
+
const parameters = this.visitNodes(node.parameters);
|
|
1115
|
+
const body = this.visitNode(node.body);
|
|
1116
|
+
this.exitClassElement();
|
|
1117
|
+
return this.finishClassElement(this.factory.updateMethodDeclaration(node, result.modifiers, node.asteriskToken, result.name, undefined, undefined, parameters, undefined, undefined, body), node);
|
|
1118
|
+
}
|
|
1119
|
+
visitGetAccessorDeclaration(node) {
|
|
1120
|
+
this.enterClassElement(node);
|
|
1121
|
+
const result = this.partialTransformClassElement(node, this.classInfo, 2 /* DescriptorKind.GetAccessor */);
|
|
1122
|
+
if (result.descriptorName !== undefined) {
|
|
1123
|
+
this.exitClassElement();
|
|
1124
|
+
return this.finishClassElement(this.createGetAccessorDescriptorForwarder(result.modifiers, result.name, result.descriptorName), node);
|
|
1125
|
+
}
|
|
1126
|
+
const parameters = this.visitNodes(node.parameters);
|
|
1127
|
+
const body = this.visitNode(node.body);
|
|
1128
|
+
this.exitClassElement();
|
|
1129
|
+
return this.finishClassElement(this.factory.updateGetAccessorDeclaration(node, result.modifiers, result.name, undefined, parameters, undefined, undefined, body), node);
|
|
1130
|
+
}
|
|
1131
|
+
visitSetAccessorDeclaration(node) {
|
|
1132
|
+
this.enterClassElement(node);
|
|
1133
|
+
const result = this.partialTransformClassElement(node, this.classInfo, 3 /* DescriptorKind.SetAccessor */);
|
|
1134
|
+
if (result.descriptorName !== undefined) {
|
|
1135
|
+
this.exitClassElement();
|
|
1136
|
+
return this.finishClassElement(this.createSetAccessorDescriptorForwarder(result.modifiers, result.name, result.descriptorName), node);
|
|
1137
|
+
}
|
|
1138
|
+
const parameters = this.visitNodes(node.parameters);
|
|
1139
|
+
const body = this.visitNode(node.body);
|
|
1140
|
+
this.exitClassElement();
|
|
1141
|
+
return this.finishClassElement(this.factory.updateSetAccessorDeclaration(node, result.modifiers, result.name, undefined, parameters, undefined, undefined, body), node);
|
|
1142
|
+
}
|
|
1143
|
+
visitClassStaticBlockDeclaration(node) {
|
|
1144
|
+
const original = node;
|
|
1145
|
+
this.enterClassElement(node);
|
|
1146
|
+
const factory = this.factory;
|
|
1147
|
+
const context = this.context;
|
|
1148
|
+
let result;
|
|
1149
|
+
if (isClassNamedEvaluationHelperBlock(context, node)) {
|
|
1150
|
+
result = this.visitEachChild(node);
|
|
1151
|
+
// Keeps the block recognizable after `this` became `_classThis`.
|
|
1152
|
+
const assignedName = context.getAssignedName(node);
|
|
1153
|
+
if (assignedName !== undefined && result !== original)
|
|
1154
|
+
context.setAssignedName(result, assignedName);
|
|
1155
|
+
}
|
|
1156
|
+
else if (isClassThisAssignmentBlock(context, node)) {
|
|
1157
|
+
const savedClassThis = this.classThis;
|
|
1158
|
+
this.classThis = undefined;
|
|
1159
|
+
result = this.visitEachChild(node);
|
|
1160
|
+
this.classThis = savedClassThis;
|
|
1161
|
+
}
|
|
1162
|
+
else {
|
|
1163
|
+
// Temporaries of the block's contents stay scoped to the block.
|
|
1164
|
+
context.startVariableEnvironment();
|
|
1165
|
+
result = this.visitEachChild(node);
|
|
1166
|
+
const declarations = context.endVariableEnvironment();
|
|
1167
|
+
if (declarations.length > 0 && result instanceof ClassStaticBlockDeclaration) {
|
|
1168
|
+
const body = result.body;
|
|
1169
|
+
result = factory.created(new ClassStaticBlockDeclaration(undefined, factory.createBlock(declarations.concat(body.statements.nodes), body.multiLine)));
|
|
1170
|
+
}
|
|
1171
|
+
const info = this.classInfo;
|
|
1172
|
+
if (info !== undefined) {
|
|
1173
|
+
info.hasStaticInitializers = true;
|
|
1174
|
+
if (info.pendingStaticInitializers.length > 0) {
|
|
1175
|
+
// Pending initializers get a block of their own, so names don't collide with this one's.
|
|
1176
|
+
const statements = [];
|
|
1177
|
+
for (let i = 0; i < info.pendingStaticInitializers.length; i++) {
|
|
1178
|
+
const initializer = info.pendingStaticInitializers[i];
|
|
1179
|
+
const statement = factory.createExpressionStatement(initializer);
|
|
1180
|
+
context.setSourceMapRange(statement, context.sourceMapPos(initializer), context.sourceMapEnd(initializer));
|
|
1181
|
+
statements.push(statement);
|
|
1182
|
+
}
|
|
1183
|
+
const staticBlock = factory.created(new ClassStaticBlockDeclaration(undefined, factory.createBlock(statements, true)));
|
|
1184
|
+
info.pendingStaticInitializers = [];
|
|
1185
|
+
this.exitClassElement();
|
|
1186
|
+
return singleOrMany([staticBlock, result], factory);
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
this.exitClassElement();
|
|
1191
|
+
return result;
|
|
1192
|
+
}
|
|
1193
|
+
visitPropertyDeclaration(original) {
|
|
1194
|
+
const factory = this.factory;
|
|
1195
|
+
const context = this.context;
|
|
1196
|
+
let node = original;
|
|
1197
|
+
if (isNamedEvaluation(context, node, anonymousDecoratedClass))
|
|
1198
|
+
node = transformNamedEvaluation(context, node, canIgnoreEmptyStringLiteralInAssignedName(node.initializer), '');
|
|
1199
|
+
this.enterClassElement(node);
|
|
1200
|
+
const isAccessor = hasSyntacticModifier(node, 512 /* ModifierFlags.Accessor */);
|
|
1201
|
+
const result = this.partialTransformClassElement(node, this.classInfo, isAccessor ? 4 /* DescriptorKind.AccessorProperty */ : 0 /* DescriptorKind.None */);
|
|
1202
|
+
context.startVariableEnvironment();
|
|
1203
|
+
let initializer = this.visitNode(node.initializer);
|
|
1204
|
+
if (result.initializersName !== undefined)
|
|
1205
|
+
initializer = createRunInitializersHelper(factory, result.thisArg !== undefined ? result.thisArg : factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), result.initializersName, initializer !== undefined ? initializer : factory.createVoidZero());
|
|
1206
|
+
const info = this.classInfo;
|
|
1207
|
+
if (isStatic(node) && info !== undefined && initializer !== undefined)
|
|
1208
|
+
info.hasStaticInitializers = true;
|
|
1209
|
+
const declarations = context.endVariableEnvironment();
|
|
1210
|
+
if (declarations.length > 0) {
|
|
1211
|
+
declarations.push(factory.createReturnStatement(initializer));
|
|
1212
|
+
initializer = factory.createImmediatelyInvokedArrowFunction(declarations);
|
|
1213
|
+
}
|
|
1214
|
+
if (info !== undefined) {
|
|
1215
|
+
if (isStatic(node)) {
|
|
1216
|
+
initializer = this.injectPendingInitializers(info, true, initializer);
|
|
1217
|
+
if (result.extraInitializersName !== undefined)
|
|
1218
|
+
info.pendingStaticInitializers.push(createRunInitializersHelper(factory, info.classThis !== undefined ? info.classThis : factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), result.extraInitializersName, undefined));
|
|
1219
|
+
}
|
|
1220
|
+
else {
|
|
1221
|
+
initializer = this.injectPendingInitializers(info, false, initializer);
|
|
1222
|
+
if (result.extraInitializersName !== undefined)
|
|
1223
|
+
info.pendingInstanceInitializers.push(createRunInitializersHelper(factory, factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), result.extraInitializersName, undefined));
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
this.exitClassElement();
|
|
1227
|
+
if (isAccessor && result.descriptorName !== undefined) {
|
|
1228
|
+
// `accessor #x = 1;` becomes a backing field and forwarders to the decorated descriptor:
|
|
1229
|
+
// #x_accessor_storage = 1;
|
|
1230
|
+
// get #x() { return _private_x_descriptor.get.call(this); }
|
|
1231
|
+
// set #x(value) { _private_x_descriptor.set.call(this, value); }
|
|
1232
|
+
const commentPos = context.commentPos(node);
|
|
1233
|
+
const commentEnd = context.commentEnd(node);
|
|
1234
|
+
const sourceMapPos = context.sourceMapPos(node);
|
|
1235
|
+
const sourceMapEnd = context.sourceMapEnd(node);
|
|
1236
|
+
// Two declarations replace one, so a computed name is cached.
|
|
1237
|
+
const propertyName = node.name;
|
|
1238
|
+
let getterName = result.name;
|
|
1239
|
+
let setterName = result.name;
|
|
1240
|
+
if (propertyName instanceof ComputedPropertyName && !isSimpleInlineableExpression(propertyName.expression)) {
|
|
1241
|
+
const cacheAssignment = findComputedPropertyNameCacheAssignment(propertyName);
|
|
1242
|
+
if (cacheAssignment !== undefined) {
|
|
1243
|
+
getterName = factory.updateComputedPropertyName(propertyName, this.visitNode(propertyName.expression));
|
|
1244
|
+
setterName = factory.updateComputedPropertyName(propertyName, cacheAssignment.left);
|
|
1245
|
+
}
|
|
1246
|
+
else {
|
|
1247
|
+
const temp = factory.createTempVariable(0);
|
|
1248
|
+
const expressionNode = propertyName.expression;
|
|
1249
|
+
context.setSourceMapRange(temp, expressionNode.pos, expressionNode.end);
|
|
1250
|
+
context.addVariableDeclaration(temp);
|
|
1251
|
+
const assignment = factory.createAssignment(temp, this.visitNode(expressionNode));
|
|
1252
|
+
context.setSourceMapRange(assignment, expressionNode.pos, expressionNode.end);
|
|
1253
|
+
getterName = factory.updateComputedPropertyName(propertyName, assignment);
|
|
1254
|
+
setterName = factory.updateComputedPropertyName(propertyName, temp);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
const modifiers = this.filterModifiers(result.modifiers, 4 /* ModifierFilter.NoAccessor */);
|
|
1258
|
+
const backingField = createAccessorPropertyBackingField(factory, node, modifiers, initializer);
|
|
1259
|
+
context.setOriginal(backingField, node);
|
|
1260
|
+
context.setEmitFlags(backingField, 384 /* EmitFlags.NoComments */);
|
|
1261
|
+
context.setSourceMapRange(backingField, sourceMapPos, sourceMapEnd);
|
|
1262
|
+
const backingFieldName = getName(backingField);
|
|
1263
|
+
context.setSourceMapRange(backingFieldName, context.sourceMapPos(node.name), context.sourceMapEnd(node.name));
|
|
1264
|
+
const getter = this.createGetAccessorDescriptorForwarder(modifiers, getterName, result.descriptorName);
|
|
1265
|
+
context.setOriginal(getter, node);
|
|
1266
|
+
context.setCommentRange(getter, commentPos, commentEnd);
|
|
1267
|
+
context.setSourceMapRange(getter, sourceMapPos, sourceMapEnd);
|
|
1268
|
+
const setter = this.createSetAccessorDescriptorForwarder(modifiers, setterName, result.descriptorName);
|
|
1269
|
+
context.setOriginal(setter, node);
|
|
1270
|
+
context.setEmitFlags(setter, 384 /* EmitFlags.NoComments */);
|
|
1271
|
+
context.setSourceMapRange(setter, sourceMapPos, sourceMapEnd);
|
|
1272
|
+
const declarations = [];
|
|
1273
|
+
declarations.push(backingField);
|
|
1274
|
+
declarations.push(getter);
|
|
1275
|
+
declarations.push(setter);
|
|
1276
|
+
return factory.createSyntaxList(declarations);
|
|
1277
|
+
}
|
|
1278
|
+
return this.finishClassElement(factory.updatePropertyDeclaration(node, result.modifiers, result.name, undefined, undefined, initializer), node);
|
|
1279
|
+
}
|
|
1280
|
+
// `super` and `this` in static initializers
|
|
1281
|
+
visitCallExpression(node) {
|
|
1282
|
+
if (isSuperProperty(node.expression) && this.classThis !== undefined) {
|
|
1283
|
+
const expression = this.visitNode(node.expression);
|
|
1284
|
+
const args = this.visitNodes(node.arguments);
|
|
1285
|
+
const invocation = this.factory.createFunctionCallCall(expression, this.classThis, args.nodes);
|
|
1286
|
+
this.context.setOriginal(invocation, node);
|
|
1287
|
+
invocation.pos = node.pos;
|
|
1288
|
+
invocation.end = node.end;
|
|
1289
|
+
return invocation;
|
|
1290
|
+
}
|
|
1291
|
+
return this.visitEachChild(node);
|
|
1292
|
+
}
|
|
1293
|
+
visitTaggedTemplateExpression(node) {
|
|
1294
|
+
if (isSuperProperty(node.tag) && this.classThis !== undefined) {
|
|
1295
|
+
const tag = this.visitNode(node.tag);
|
|
1296
|
+
const boundTag = this.factory.createFunctionBindCall(tag, this.classThis, []);
|
|
1297
|
+
this.context.setOriginal(boundTag, node);
|
|
1298
|
+
boundTag.pos = node.pos;
|
|
1299
|
+
boundTag.end = node.end;
|
|
1300
|
+
const template = this.visitNode(node.template);
|
|
1301
|
+
return this.factory.updateTaggedTemplateExpression(node, boundTag, undefined, undefined, template, node.flags);
|
|
1302
|
+
}
|
|
1303
|
+
return this.visitEachChild(node);
|
|
1304
|
+
}
|
|
1305
|
+
visitPropertyAccessExpression(node) {
|
|
1306
|
+
if (isSuperProperty(node) &&
|
|
1307
|
+
node.name instanceof Identifier &&
|
|
1308
|
+
this.classThis !== undefined &&
|
|
1309
|
+
this.classSuper !== undefined) {
|
|
1310
|
+
const superProperty = this.factory.createReflectGetCall(this.classSuper, this.factory.createStringLiteralFromNode(node.name), this.classThis);
|
|
1311
|
+
this.context.setOriginal(superProperty, node.expression);
|
|
1312
|
+
superProperty.pos = node.expression.pos;
|
|
1313
|
+
superProperty.end = node.expression.end;
|
|
1314
|
+
return superProperty;
|
|
1315
|
+
}
|
|
1316
|
+
return this.visitEachChild(node);
|
|
1317
|
+
}
|
|
1318
|
+
visitElementAccessExpression(node) {
|
|
1319
|
+
if (isSuperProperty(node) && this.classThis !== undefined && this.classSuper !== undefined) {
|
|
1320
|
+
const superProperty = this.factory.createReflectGetCall(this.classSuper, this.visitNode(node.argumentExpression), this.classThis);
|
|
1321
|
+
this.context.setOriginal(superProperty, node.expression);
|
|
1322
|
+
superProperty.pos = node.expression.pos;
|
|
1323
|
+
superProperty.end = node.expression.end;
|
|
1324
|
+
return superProperty;
|
|
1325
|
+
}
|
|
1326
|
+
return this.visitEachChild(node);
|
|
1327
|
+
}
|
|
1328
|
+
// NamedEvaluation sites
|
|
1329
|
+
visitParameterDeclaration(original) {
|
|
1330
|
+
const context = this.context;
|
|
1331
|
+
let node = original;
|
|
1332
|
+
if (isNamedEvaluation(context, node, anonymousDecoratedClass))
|
|
1333
|
+
node = transformNamedEvaluation(context, node, canIgnoreEmptyStringLiteralInAssignedName(node.initializer), '');
|
|
1334
|
+
// Drops all modifiers, decorators included.
|
|
1335
|
+
const updated = this.factory.updateParameterDeclaration(node, undefined, node.dotDotDotToken, this.visitNode(node.name), undefined, undefined, this.visitNode(node.initializer));
|
|
1336
|
+
if (updated !== node) {
|
|
1337
|
+
// Source maps start past the modifiers, but comments cover the original range.
|
|
1338
|
+
context.setCommentRange(updated, node.pos, node.end);
|
|
1339
|
+
const pos = moveRangePastModifiers(node).pos;
|
|
1340
|
+
updated.pos = pos | 0;
|
|
1341
|
+
updated.end = node.end;
|
|
1342
|
+
context.setSourceMapRange(updated, pos, node.end);
|
|
1343
|
+
context.setEmitFlags(updated.name, 8 /* EmitFlags.NoTrailingSourceMap */);
|
|
1344
|
+
}
|
|
1345
|
+
return updated;
|
|
1346
|
+
}
|
|
1347
|
+
visitNamedEvaluationSite(node, value) {
|
|
1348
|
+
if (isNamedEvaluation(this.context, node, anonymousDecoratedClass))
|
|
1349
|
+
node = transformNamedEvaluation(this.context, node, canIgnoreEmptyStringLiteralInAssignedName(value), '');
|
|
1350
|
+
return this.visitEachChild(node);
|
|
1351
|
+
}
|
|
1352
|
+
visitForStatement(node) {
|
|
1353
|
+
return this.factory.updateForStatement(node, this.visitDiscardedNode(node.initializer), this.visitNode(node.condition), this.visitDiscardedNode(node.incrementor), this.visitIterationBody(node.statement));
|
|
1354
|
+
}
|
|
1355
|
+
visitBinaryExpression(node, discarded) {
|
|
1356
|
+
const factory = this.factory;
|
|
1357
|
+
const context = this.context;
|
|
1358
|
+
if (isDestructuringAssignment(node)) {
|
|
1359
|
+
const left = this.visitAssignmentPattern(node.left);
|
|
1360
|
+
const right = this.visitNode(node.right);
|
|
1361
|
+
return factory.updateBinaryExpression(node, undefined, left, undefined, node.operatorToken, right);
|
|
1362
|
+
}
|
|
1363
|
+
if (isAssignmentExpression(node, false)) {
|
|
1364
|
+
if (isNamedEvaluation(context, node, anonymousDecoratedClass))
|
|
1365
|
+
return this.visitEachChild(transformNamedEvaluation(context, node, canIgnoreEmptyStringLiteralInAssignedName(node.right), ''));
|
|
1366
|
+
const left = node.left;
|
|
1367
|
+
if (isSuperProperty(left) && this.classThis !== undefined && this.classSuper !== undefined) {
|
|
1368
|
+
let setterName = undefined;
|
|
1369
|
+
if (left instanceof ElementAccessExpression)
|
|
1370
|
+
setterName = this.visitNode(left.argumentExpression);
|
|
1371
|
+
else if (left instanceof PropertyAccessExpression && left.name instanceof Identifier)
|
|
1372
|
+
setterName = factory.createStringLiteralFromNode(left.name);
|
|
1373
|
+
if (setterName !== undefined) {
|
|
1374
|
+
// super.x = ... super.x += ... super[x] = ... super[x] += ...
|
|
1375
|
+
let expression = this.visitNode(node.right);
|
|
1376
|
+
if (isCompoundAssignment(node.operatorToken.kind)) {
|
|
1377
|
+
let getterName = setterName;
|
|
1378
|
+
if (!isSimpleInlineableExpression(setterName)) {
|
|
1379
|
+
const temp = factory.createTempVariable(0);
|
|
1380
|
+
context.addVariableDeclaration(temp);
|
|
1381
|
+
getterName = temp;
|
|
1382
|
+
setterName = factory.createAssignment(temp, setterName);
|
|
1383
|
+
}
|
|
1384
|
+
const superPropertyGet = factory.createReflectGetCall(this.classSuper, getterName, this.classThis);
|
|
1385
|
+
context.setOriginal(superPropertyGet, left);
|
|
1386
|
+
superPropertyGet.pos = left.pos;
|
|
1387
|
+
superPropertyGet.end = left.end;
|
|
1388
|
+
expression = factory.createBinaryExpression(superPropertyGet, getNonAssignmentOperatorForCompoundAssignment(node.operatorToken.kind), expression);
|
|
1389
|
+
expression.pos = node.pos;
|
|
1390
|
+
expression.end = node.end;
|
|
1391
|
+
}
|
|
1392
|
+
let temp = undefined;
|
|
1393
|
+
if (!discarded) {
|
|
1394
|
+
temp = factory.createTempVariable(0);
|
|
1395
|
+
context.addVariableDeclaration(temp);
|
|
1396
|
+
expression = factory.createAssignment(temp, expression);
|
|
1397
|
+
expression.pos = node.pos;
|
|
1398
|
+
expression.end = node.end;
|
|
1399
|
+
}
|
|
1400
|
+
expression = factory.createReflectSetCall(this.classSuper, setterName, expression, this.classThis);
|
|
1401
|
+
context.setOriginal(expression, node);
|
|
1402
|
+
expression.pos = node.pos;
|
|
1403
|
+
expression.end = node.end;
|
|
1404
|
+
if (temp !== undefined) {
|
|
1405
|
+
expression = factory.createCommaExpression(expression, temp);
|
|
1406
|
+
expression.pos = node.pos;
|
|
1407
|
+
expression.end = node.end;
|
|
1408
|
+
}
|
|
1409
|
+
return expression;
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
if (node.operatorToken.kind === 27 /* SyntaxKind.CommaToken */) {
|
|
1414
|
+
const left = this.visitDiscarded(node.left);
|
|
1415
|
+
const right = discarded ? this.visitDiscarded(node.right) : this.visitNode(node.right);
|
|
1416
|
+
return factory.updateBinaryExpression(node, undefined, left, undefined, node.operatorToken, right);
|
|
1417
|
+
}
|
|
1418
|
+
return this.visitEachChild(node);
|
|
1419
|
+
}
|
|
1420
|
+
visitPreOrPostfixUnaryExpression(node, discarded) {
|
|
1421
|
+
const factory = this.factory;
|
|
1422
|
+
const context = this.context;
|
|
1423
|
+
let operator = 0 /* SyntaxKind.Unknown */;
|
|
1424
|
+
let operandNode = undefined;
|
|
1425
|
+
if (node instanceof PrefixUnaryExpression) {
|
|
1426
|
+
operator = node.operator;
|
|
1427
|
+
operandNode = node.operand;
|
|
1428
|
+
}
|
|
1429
|
+
else if (node instanceof PostfixUnaryExpression) {
|
|
1430
|
+
operator = node.operator;
|
|
1431
|
+
operandNode = node.operand;
|
|
1432
|
+
}
|
|
1433
|
+
if (operandNode !== undefined &&
|
|
1434
|
+
(operator === 45 /* SyntaxKind.PlusPlusToken */ || operator === 46 /* SyntaxKind.MinusMinusToken */)) {
|
|
1435
|
+
const operand = skipParentheses(operandNode);
|
|
1436
|
+
if (isSuperProperty(operand) && this.classThis !== undefined && this.classSuper !== undefined) {
|
|
1437
|
+
let setterName = undefined;
|
|
1438
|
+
if (operand instanceof ElementAccessExpression)
|
|
1439
|
+
setterName = this.visitNode(operand.argumentExpression);
|
|
1440
|
+
else if (operand instanceof PropertyAccessExpression && operand.name instanceof Identifier)
|
|
1441
|
+
setterName = factory.createStringLiteralFromNode(operand.name);
|
|
1442
|
+
if (setterName !== undefined) {
|
|
1443
|
+
let getterName = setterName;
|
|
1444
|
+
if (!isSimpleInlineableExpression(setterName)) {
|
|
1445
|
+
const temp = factory.createTempVariable(0);
|
|
1446
|
+
context.addVariableDeclaration(temp);
|
|
1447
|
+
getterName = temp;
|
|
1448
|
+
setterName = factory.createAssignment(temp, setterName);
|
|
1449
|
+
}
|
|
1450
|
+
let expression = factory.createReflectGetCall(this.classSuper, getterName, this.classThis);
|
|
1451
|
+
context.setOriginal(expression, node);
|
|
1452
|
+
expression.pos = node.pos;
|
|
1453
|
+
expression.end = node.end;
|
|
1454
|
+
// A discarded result needs no temporary for it:
|
|
1455
|
+
// super.x++; => _a = Reflect.get(_super, "x"), _a++, Reflect.set(_super, "x", _a);
|
|
1456
|
+
// y = super.x++; => y = (_a = Reflect.get(_super, "x"), _b = _a++, Reflect.set(_super, "x", _a), _b);
|
|
1457
|
+
let temp = undefined;
|
|
1458
|
+
if (!discarded) {
|
|
1459
|
+
temp = factory.createTempVariable(0);
|
|
1460
|
+
context.addVariableDeclaration(temp);
|
|
1461
|
+
}
|
|
1462
|
+
expression = expandPreOrPostfixIncrementOrDecrementExpression(context, node, expression, temp);
|
|
1463
|
+
expression = factory.createReflectSetCall(this.classSuper, setterName, expression, this.classThis);
|
|
1464
|
+
context.setOriginal(expression, node);
|
|
1465
|
+
expression.pos = node.pos;
|
|
1466
|
+
expression.end = node.end;
|
|
1467
|
+
if (temp !== undefined) {
|
|
1468
|
+
expression = factory.createCommaExpression(expression, temp);
|
|
1469
|
+
expression.pos = node.pos;
|
|
1470
|
+
expression.end = node.end;
|
|
1471
|
+
}
|
|
1472
|
+
return expression;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
return this.visitEachChild(node);
|
|
1477
|
+
}
|
|
1478
|
+
// Property names
|
|
1479
|
+
/** Sets the result's referenced name, for the decorator context, and its visited name. */
|
|
1480
|
+
visitReferencedPropertyName(node, result) {
|
|
1481
|
+
const factory = this.factory;
|
|
1482
|
+
if (isPropertyNameLiteral(node) || node instanceof PrivateIdentifier) {
|
|
1483
|
+
result.referencedName = factory.createStringLiteralFromNode(node);
|
|
1484
|
+
result.name = this.visitNode(node);
|
|
1485
|
+
return true;
|
|
1486
|
+
}
|
|
1487
|
+
if (!(node instanceof ComputedPropertyName))
|
|
1488
|
+
return false;
|
|
1489
|
+
const expression = node.expression;
|
|
1490
|
+
if (isPropertyNameLiteral(expression) && !(expression instanceof Identifier)) {
|
|
1491
|
+
result.referencedName = factory.createStringLiteralFromNode(expression);
|
|
1492
|
+
result.name = this.visitNode(node);
|
|
1493
|
+
return true;
|
|
1494
|
+
}
|
|
1495
|
+
const referencedName = factory.createGeneratedNameForNode(node, 0, '', '');
|
|
1496
|
+
this.context.addVariableDeclaration(referencedName);
|
|
1497
|
+
const key = createPropKeyHelper(factory, this.visitNode(expression));
|
|
1498
|
+
const assignment = factory.createAssignment(referencedName, key);
|
|
1499
|
+
result.referencedName = referencedName;
|
|
1500
|
+
result.name = factory.updateComputedPropertyName(node, this.injectPendingExpressions(assignment));
|
|
1501
|
+
return true;
|
|
1502
|
+
}
|
|
1503
|
+
visitPropertyName(node) {
|
|
1504
|
+
if (node instanceof ComputedPropertyName)
|
|
1505
|
+
return this.visitComputedPropertyName(node);
|
|
1506
|
+
return this.visitNode(node);
|
|
1507
|
+
}
|
|
1508
|
+
visitComputedPropertyName(node) {
|
|
1509
|
+
let expression = this.visitNode(node.expression);
|
|
1510
|
+
if (!isSimpleInlineableExpression(expression))
|
|
1511
|
+
expression = this.injectPendingExpressions(expression);
|
|
1512
|
+
return this.factory.updateComputedPropertyName(node, expression);
|
|
1513
|
+
}
|
|
1514
|
+
// Destructuring assignments
|
|
1515
|
+
visitDestructuringAssignmentTarget(node) {
|
|
1516
|
+
if (node instanceof ObjectLiteralExpression || node instanceof ArrayLiteralExpression)
|
|
1517
|
+
return this.visitAssignmentPattern(node);
|
|
1518
|
+
if (isSuperProperty(node) && this.classThis !== undefined && this.classSuper !== undefined) {
|
|
1519
|
+
const factory = this.factory;
|
|
1520
|
+
let propertyName = undefined;
|
|
1521
|
+
if (node instanceof ElementAccessExpression)
|
|
1522
|
+
propertyName = this.visitNode(node.argumentExpression);
|
|
1523
|
+
else if (node instanceof PropertyAccessExpression && node.name instanceof Identifier)
|
|
1524
|
+
propertyName = factory.createStringLiteralFromNode(node.name);
|
|
1525
|
+
if (propertyName !== undefined) {
|
|
1526
|
+
const paramName = factory.createTempVariable(0);
|
|
1527
|
+
const expression = factory.createAssignmentTargetWrapper(paramName, factory.createReflectSetCall(this.classSuper, propertyName, paramName, this.classThis));
|
|
1528
|
+
this.context.setOriginal(expression, node);
|
|
1529
|
+
expression.pos = node.pos;
|
|
1530
|
+
expression.end = node.end;
|
|
1531
|
+
return expression;
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
return this.visitEachChild(node);
|
|
1535
|
+
}
|
|
1536
|
+
visitAssignmentElement(node) {
|
|
1537
|
+
if (node instanceof BinaryExpression && isAssignmentExpression(node, true)) {
|
|
1538
|
+
let assignment = node;
|
|
1539
|
+
if (isNamedEvaluation(this.context, assignment, anonymousDecoratedClass))
|
|
1540
|
+
assignment = transformNamedEvaluation(this.context, assignment, canIgnoreEmptyStringLiteralInAssignedName(assignment.right), '');
|
|
1541
|
+
const target = this.visitDestructuringAssignmentTarget(assignment.left);
|
|
1542
|
+
const initializer = this.visitNode(assignment.right);
|
|
1543
|
+
return this.factory.updateBinaryExpression(assignment, undefined, target, undefined, assignment.operatorToken, initializer);
|
|
1544
|
+
}
|
|
1545
|
+
return this.visitDestructuringAssignmentTarget(node);
|
|
1546
|
+
}
|
|
1547
|
+
visitArrayAssignmentElement(node) {
|
|
1548
|
+
if (node instanceof SpreadElement) {
|
|
1549
|
+
const spread = node;
|
|
1550
|
+
if (isLeftHandSideExpression(spread.expression))
|
|
1551
|
+
return this.factory.updateSpreadElement(spread, this.visitDestructuringAssignmentTarget(spread.expression));
|
|
1552
|
+
return this.visitEachChild(node);
|
|
1553
|
+
}
|
|
1554
|
+
if (node.kind !== 233 /* SyntaxKind.OmittedExpression */)
|
|
1555
|
+
return this.visitAssignmentElement(node);
|
|
1556
|
+
return this.visitEachChild(node);
|
|
1557
|
+
}
|
|
1558
|
+
visitObjectAssignmentElement(node) {
|
|
1559
|
+
const factory = this.factory;
|
|
1560
|
+
if (node instanceof SpreadAssignment) {
|
|
1561
|
+
const spread = node;
|
|
1562
|
+
if (isLeftHandSideExpression(spread.expression))
|
|
1563
|
+
return factory.updateSpreadAssignment(spread, this.visitDestructuringAssignmentTarget(spread.expression));
|
|
1564
|
+
return this.visitEachChild(node);
|
|
1565
|
+
}
|
|
1566
|
+
if (node instanceof ShorthandPropertyAssignment) {
|
|
1567
|
+
const shorthand = node;
|
|
1568
|
+
let property = shorthand;
|
|
1569
|
+
if (isNamedEvaluation(this.context, shorthand, anonymousDecoratedClass))
|
|
1570
|
+
property = transformNamedEvaluation(this.context, shorthand, canIgnoreEmptyStringLiteralInAssignedName(shorthand.objectAssignmentInitializer), '');
|
|
1571
|
+
return this.visitEachChild(property);
|
|
1572
|
+
}
|
|
1573
|
+
if (node instanceof PropertyAssignment) {
|
|
1574
|
+
const property = node;
|
|
1575
|
+
const name = this.visitNode(property.name);
|
|
1576
|
+
if (isAssignmentExpression(property.initializer, true))
|
|
1577
|
+
return factory.updatePropertyAssignment(property, undefined, name, undefined, undefined, this.visitAssignmentElement(property.initializer));
|
|
1578
|
+
if (isLeftHandSideExpression(property.initializer))
|
|
1579
|
+
return factory.updatePropertyAssignment(property, undefined, name, undefined, undefined, this.visitDestructuringAssignmentTarget(property.initializer));
|
|
1580
|
+
}
|
|
1581
|
+
return this.visitEachChild(node);
|
|
1582
|
+
}
|
|
1583
|
+
visitAssignmentPattern(node) {
|
|
1584
|
+
if (node instanceof ArrayLiteralExpression) {
|
|
1585
|
+
const array = node;
|
|
1586
|
+
return this.factory.updateArrayLiteralExpression(array, this.visitList(array.elements, 3 /* ListVisit.ArrayAssignmentElements */), array.multiLine);
|
|
1587
|
+
}
|
|
1588
|
+
if (node instanceof ObjectLiteralExpression) {
|
|
1589
|
+
const object = node;
|
|
1590
|
+
return this.factory.updateObjectLiteralExpression(object, this.visitList(object.properties, 4 /* ListVisit.ObjectAssignmentElements */), object.multiLine);
|
|
1591
|
+
}
|
|
1592
|
+
return node;
|
|
1593
|
+
}
|
|
1594
|
+
visitParenthesizedExpression(node, discarded) {
|
|
1595
|
+
const expression = discarded ? this.visitDiscarded(node.expression) : this.visitNode(node.expression);
|
|
1596
|
+
return this.factory.updateParenthesizedExpression(node, expression);
|
|
1597
|
+
}
|
|
1598
|
+
visitPartiallyEmittedExpression(node, discarded) {
|
|
1599
|
+
const expression = discarded ? this.visitDiscarded(node.expression) : this.visitNode(node.expression);
|
|
1600
|
+
return this.factory.updatePartiallyEmittedExpression(node, expression);
|
|
1601
|
+
}
|
|
1602
|
+
// Pending expressions
|
|
1603
|
+
/** `pending` evaluated before `expression`, inside its parentheses. */
|
|
1604
|
+
prependExpressions(pending, expression) {
|
|
1605
|
+
const factory = this.factory;
|
|
1606
|
+
if (pending.length === 0)
|
|
1607
|
+
return expression;
|
|
1608
|
+
if (expression === undefined)
|
|
1609
|
+
return factory.inlineExpressions(pending);
|
|
1610
|
+
if (expression instanceof ParenthesizedExpression)
|
|
1611
|
+
return factory.updateParenthesizedExpression(expression, factory.inlineExpressions(pending.concat([expression.expression])));
|
|
1612
|
+
return factory.inlineExpressions(pending.concat([expression]));
|
|
1613
|
+
}
|
|
1614
|
+
injectPendingExpressions(expression) {
|
|
1615
|
+
const result = this.prependExpressions(this.pendingExpressions, expression);
|
|
1616
|
+
if (result !== expression)
|
|
1617
|
+
this.pendingExpressions = [];
|
|
1618
|
+
return result;
|
|
1619
|
+
}
|
|
1620
|
+
injectPendingInitializers(info, isStaticMember, expression) {
|
|
1621
|
+
if (isStaticMember) {
|
|
1622
|
+
const result = this.prependExpressions(info.pendingStaticInitializers, expression);
|
|
1623
|
+
if (result !== expression)
|
|
1624
|
+
info.pendingStaticInitializers = [];
|
|
1625
|
+
return result;
|
|
1626
|
+
}
|
|
1627
|
+
const result = this.prependExpressions(info.pendingInstanceInitializers, expression);
|
|
1628
|
+
if (result !== expression)
|
|
1629
|
+
info.pendingInstanceInitializers = [];
|
|
1630
|
+
return result;
|
|
1631
|
+
}
|
|
1632
|
+
// Decorators
|
|
1633
|
+
transformAllDecoratorsOfDeclaration(decorators) {
|
|
1634
|
+
const result = [];
|
|
1635
|
+
for (let i = 0; i < decorators.length; i++) {
|
|
1636
|
+
const decorator = decorators[i];
|
|
1637
|
+
if (decorator instanceof Decorator)
|
|
1638
|
+
result.push(this.transformDecorator(decorator));
|
|
1639
|
+
}
|
|
1640
|
+
return result;
|
|
1641
|
+
}
|
|
1642
|
+
transformDecorator(decorator) {
|
|
1643
|
+
const expression = this.visitNode(decorator.expression);
|
|
1644
|
+
this.context.setEmitFlags(expression, 384 /* EmitFlags.NoComments */);
|
|
1645
|
+
// An access expression keeps its `this`.
|
|
1646
|
+
const inner = skipOuterExpressions(expression, 63 /* OuterExpressionKinds.All */);
|
|
1647
|
+
if (inner instanceof PropertyAccessExpression || inner instanceof ElementAccessExpression) {
|
|
1648
|
+
const bound = this.createCallBinding(expression);
|
|
1649
|
+
return this.context.factory.restoreOuterExpressions(expression, this.factory.createFunctionBindCall(bound.target, bound.thisArg, []), 63 /* OuterExpressionKinds.All */);
|
|
1650
|
+
}
|
|
1651
|
+
return expression;
|
|
1652
|
+
}
|
|
1653
|
+
createCallBinding(expression) {
|
|
1654
|
+
const factory = this.factory;
|
|
1655
|
+
const callee = skipOuterExpressions(expression, 63 /* OuterExpressionKinds.All */);
|
|
1656
|
+
if (isSuperProperty(callee) || callee.kind === 107 /* SyntaxKind.SuperKeyword */)
|
|
1657
|
+
return new CallBinding(callee, factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */));
|
|
1658
|
+
if ((this.context.getEmitFlags(callee) & 1024 /* EmitFlags.HelperName */) !== 0)
|
|
1659
|
+
return new CallBinding(callee, factory.createVoidZero());
|
|
1660
|
+
if (callee instanceof PropertyAccessExpression) {
|
|
1661
|
+
if (shouldBeCapturedInTempVariable(callee.expression)) {
|
|
1662
|
+
const thisArg = factory.createTempVariable(0);
|
|
1663
|
+
this.context.addVariableDeclaration(thisArg);
|
|
1664
|
+
const assignment = factory.createAssignment(thisArg, callee.expression);
|
|
1665
|
+
assignment.pos = callee.expression.pos;
|
|
1666
|
+
assignment.end = callee.expression.end;
|
|
1667
|
+
const target = factory.createPropertyAccessExpression(assignment, callee.name);
|
|
1668
|
+
target.pos = callee.pos;
|
|
1669
|
+
target.end = callee.end;
|
|
1670
|
+
return new CallBinding(target, thisArg);
|
|
1671
|
+
}
|
|
1672
|
+
return new CallBinding(callee, callee.expression);
|
|
1673
|
+
}
|
|
1674
|
+
if (callee instanceof ElementAccessExpression) {
|
|
1675
|
+
if (shouldBeCapturedInTempVariable(callee.expression)) {
|
|
1676
|
+
const thisArg = factory.createTempVariable(0);
|
|
1677
|
+
this.context.addVariableDeclaration(thisArg);
|
|
1678
|
+
const assignment = factory.createAssignment(thisArg, callee.expression);
|
|
1679
|
+
assignment.pos = callee.expression.pos;
|
|
1680
|
+
assignment.end = callee.expression.end;
|
|
1681
|
+
const target = factory.createElementAccessExpression(assignment, callee.argumentExpression);
|
|
1682
|
+
target.pos = callee.pos;
|
|
1683
|
+
target.end = callee.end;
|
|
1684
|
+
return new CallBinding(target, thisArg);
|
|
1685
|
+
}
|
|
1686
|
+
return new CallBinding(callee, callee.expression);
|
|
1687
|
+
}
|
|
1688
|
+
return new CallBinding(expression, factory.createVoidZero());
|
|
1689
|
+
}
|
|
1690
|
+
// Pseudo-descriptors of private elements
|
|
1691
|
+
/** A `value`, `get` or `set` method of a pseudo-descriptor: `kind: __setFunctionName(function () {}, "#x")`. */
|
|
1692
|
+
createDescriptorMethod(original, name, modifiers, asteriskToken, kind, parameters, body) {
|
|
1693
|
+
const factory = this.factory;
|
|
1694
|
+
const context = this.context;
|
|
1695
|
+
const fn = factory.created(new FunctionExpression(modifiers, asteriskToken, undefined, undefined, parameters, undefined, undefined, body !== undefined ? body : factory.createBlock([], false)));
|
|
1696
|
+
context.setOriginal(fn, original);
|
|
1697
|
+
context.setSourceMapRange(fn, moveRangePastDecorators(original).pos, original.end);
|
|
1698
|
+
context.setEmitFlags(fn, 384 /* EmitFlags.NoComments */);
|
|
1699
|
+
const prefix = kind === 'get' || kind === 'set' ? kind : '';
|
|
1700
|
+
const named = createSetFunctionNameHelper(factory, fn, factory.createStringLiteralFromNode(name), prefix);
|
|
1701
|
+
const method = factory.createPropertyAssignment(factory.createIdentifier(kind), named);
|
|
1702
|
+
context.setOriginal(method, original);
|
|
1703
|
+
context.setSourceMapRange(method, moveRangePastDecorators(original).pos, original.end);
|
|
1704
|
+
context.setEmitFlags(method, 384 /* EmitFlags.NoComments */);
|
|
1705
|
+
return method;
|
|
1706
|
+
}
|
|
1707
|
+
createDescriptorObject(kind, member, modifiers) {
|
|
1708
|
+
const factory = this.factory;
|
|
1709
|
+
const name = getName(member);
|
|
1710
|
+
const methods = [];
|
|
1711
|
+
switch (kind) {
|
|
1712
|
+
case 1 /* DescriptorKind.Method */: {
|
|
1713
|
+
const parameters = this.visitNodes(getParameters(member));
|
|
1714
|
+
const body = this.visitNode(getBody(member));
|
|
1715
|
+
const asterisk = member instanceof MethodDeclaration ? member.asteriskToken : undefined;
|
|
1716
|
+
methods.push(this.createDescriptorMethod(member, name, modifiers, asterisk, 'value', parameters, body));
|
|
1717
|
+
break;
|
|
1718
|
+
}
|
|
1719
|
+
case 2 /* DescriptorKind.GetAccessor */: {
|
|
1720
|
+
const body = this.visitNode(getBody(member));
|
|
1721
|
+
methods.push(this.createDescriptorMethod(member, name, modifiers, undefined, 'get', factory.createNodeList([]), body));
|
|
1722
|
+
break;
|
|
1723
|
+
}
|
|
1724
|
+
case 3 /* DescriptorKind.SetAccessor */: {
|
|
1725
|
+
const parameters = this.visitNodes(getParameters(member));
|
|
1726
|
+
const body = this.visitNode(getBody(member));
|
|
1727
|
+
methods.push(this.createDescriptorMethod(member, name, modifiers, undefined, 'set', parameters, body));
|
|
1728
|
+
break;
|
|
1729
|
+
}
|
|
1730
|
+
case 4 /* DescriptorKind.AccessorProperty */: {
|
|
1731
|
+
// { get() { return this.#x_accessor_storage; }, set(value) { this.#x_accessor_storage = value; } }
|
|
1732
|
+
const storage = factory.createGeneratedPrivateNameForNode(name, '', '_accessor_storage');
|
|
1733
|
+
const self = factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */);
|
|
1734
|
+
methods.push(this.createDescriptorMethod(member, name, undefined, undefined, 'get', factory.createNodeList([]), factory.createBlock([factory.createReturnStatement(factory.createPropertyAccessExpression(self, storage))], false)));
|
|
1735
|
+
methods.push(this.createDescriptorMethod(member, name, undefined, undefined, 'set', factory.createNodeList([factory.createParameter(factory.createIdentifier('value'))]), factory.createBlock([
|
|
1736
|
+
factory.createExpressionStatement(factory.createAssignment(factory.createPropertyAccessExpression(factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), storage), factory.createIdentifier('value'))),
|
|
1737
|
+
], false)));
|
|
1738
|
+
break;
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
return factory.createObjectLiteral(methods, false);
|
|
1742
|
+
}
|
|
1743
|
+
/** `get name() { return _descriptor.value; }` */
|
|
1744
|
+
createMethodDescriptorForwarder(modifiers, name, descriptorName) {
|
|
1745
|
+
const factory = this.factory;
|
|
1746
|
+
return factory.created(new GetAccessorDeclaration(this.filterModifiers(modifiers, 2 /* ModifierFilter.StaticOnly */), name, undefined, factory.createNodeList([]), undefined, undefined, factory.createBlock([
|
|
1747
|
+
factory.createReturnStatement(factory.createPropertyAccessExpression(descriptorName, factory.createIdentifier('value'))),
|
|
1748
|
+
], false)));
|
|
1749
|
+
}
|
|
1750
|
+
/** `get name() { return _descriptor.get.call(this); }` */
|
|
1751
|
+
createGetAccessorDescriptorForwarder(modifiers, name, descriptorName) {
|
|
1752
|
+
const factory = this.factory;
|
|
1753
|
+
return factory.created(new GetAccessorDeclaration(this.filterModifiers(modifiers, 2 /* ModifierFilter.StaticOnly */), name, undefined, factory.createNodeList([]), undefined, undefined, factory.createBlock([
|
|
1754
|
+
factory.createReturnStatement(factory.createFunctionCallCall(factory.createPropertyAccessExpression(descriptorName, factory.createIdentifier('get')), factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), [])),
|
|
1755
|
+
], false)));
|
|
1756
|
+
}
|
|
1757
|
+
/** `set name(value) { return _descriptor.set.call(this, value); }` */
|
|
1758
|
+
createSetAccessorDescriptorForwarder(modifiers, name, descriptorName) {
|
|
1759
|
+
const factory = this.factory;
|
|
1760
|
+
return factory.created(new SetAccessorDeclaration(this.filterModifiers(modifiers, 2 /* ModifierFilter.StaticOnly */), name, undefined, factory.createNodeList([factory.createParameter(factory.createIdentifier('value'))]), undefined, undefined, factory.createBlock([
|
|
1761
|
+
factory.createReturnStatement(factory.createFunctionCallCall(factory.createPropertyAccessExpression(descriptorName, factory.createIdentifier('set')), factory.createKeywordExpression(109 /* SyntaxKind.ThisKeyword */), [factory.createIdentifier('value')])),
|
|
1762
|
+
], false)));
|
|
1763
|
+
}
|
|
1764
|
+
// Decorator contexts and metadata
|
|
1765
|
+
createClassElementContextObject(kind, nameComputed, name, isStaticMember, isPrivate, hasGet, hasSet, metadata) {
|
|
1766
|
+
const factory = this.factory;
|
|
1767
|
+
const nameValue = !nameComputed && (name instanceof Identifier || name instanceof PrivateIdentifier)
|
|
1768
|
+
? factory.createStringLiteralFromNode(name)
|
|
1769
|
+
: name;
|
|
1770
|
+
// `has` checks `name in obj`; `get` and `set` access `obj.name` or `obj[name]`.
|
|
1771
|
+
const access = [
|
|
1772
|
+
factory.createPropertyAssignment(factory.createIdentifier('has'), factory.createArrowFunction([factory.createParameter(factory.createIdentifier('obj'))], factory.createBinaryExpression(!nameComputed && name instanceof Identifier ? factory.createStringLiteralFromNode(name) : name, 102 /* SyntaxKind.InKeyword */, factory.createIdentifier('obj')))),
|
|
1773
|
+
];
|
|
1774
|
+
if (hasGet)
|
|
1775
|
+
access.push(factory.createPropertyAssignment(factory.createIdentifier('get'), factory.createArrowFunction([factory.createParameter(factory.createIdentifier('obj'))], this.createAccess(nameComputed, name))));
|
|
1776
|
+
if (hasSet)
|
|
1777
|
+
access.push(factory.createPropertyAssignment(factory.createIdentifier('set'), factory.createArrowFunction([
|
|
1778
|
+
factory.createParameter(factory.createIdentifier('obj')),
|
|
1779
|
+
factory.createParameter(factory.createIdentifier('value')),
|
|
1780
|
+
], factory.createBlock([
|
|
1781
|
+
factory.createExpressionStatement(factory.createAssignment(this.createAccess(nameComputed, name), factory.createIdentifier('value'))),
|
|
1782
|
+
], false))));
|
|
1783
|
+
return factory.createObjectLiteral([
|
|
1784
|
+
factory.createPropertyAssignment(factory.createIdentifier('kind'), factory.createStringLiteral(kind, 0 /* TokenFlags.None */)),
|
|
1785
|
+
factory.createPropertyAssignment(factory.createIdentifier('name'), nameValue),
|
|
1786
|
+
factory.createPropertyAssignment(factory.createIdentifier('static'), factory.createKeywordExpression(isStaticMember ? 111 /* SyntaxKind.TrueKeyword */ : 96 /* SyntaxKind.FalseKeyword */)),
|
|
1787
|
+
factory.createPropertyAssignment(factory.createIdentifier('private'), factory.createKeywordExpression(isPrivate ? 111 /* SyntaxKind.TrueKeyword */ : 96 /* SyntaxKind.FalseKeyword */)),
|
|
1788
|
+
factory.createPropertyAssignment(factory.createIdentifier('access'), factory.createObjectLiteral(access, false)),
|
|
1789
|
+
factory.createPropertyAssignment(factory.createIdentifier('metadata'), metadata),
|
|
1790
|
+
], false);
|
|
1791
|
+
}
|
|
1792
|
+
createAccess(nameComputed, name) {
|
|
1793
|
+
const obj = this.factory.createIdentifier('obj');
|
|
1794
|
+
return nameComputed
|
|
1795
|
+
? this.factory.createElementAccessExpression(obj, name)
|
|
1796
|
+
: this.factory.createPropertyAccessExpression(obj, name);
|
|
1797
|
+
}
|
|
1798
|
+
/** `const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(superMetadata) : void 0;` */
|
|
1799
|
+
createMetadata(name, classSuper) {
|
|
1800
|
+
const factory = this.factory;
|
|
1801
|
+
const superMetadata = classSuper !== undefined
|
|
1802
|
+
? factory.createBinaryExpression(factory.createElementAccessExpression(classSuper, this.createSymbolMetadataAccess()), 60 /* SyntaxKind.QuestionQuestionToken */, factory.createToken(105 /* SyntaxKind.NullKeyword */))
|
|
1803
|
+
: factory.createToken(105 /* SyntaxKind.NullKeyword */);
|
|
1804
|
+
const create = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('Object'), factory.createIdentifier('create')), [superMetadata]);
|
|
1805
|
+
const symbolCheck = factory.createBinaryExpression(factory.createTypeCheck(factory.createIdentifier('Symbol'), 'function'), 55 /* SyntaxKind.AmpersandAmpersandToken */, this.createSymbolMetadataAccess());
|
|
1806
|
+
return factory.createVariableStatement(undefined, factory.createVariableDeclarationList(factory.createNodeList([
|
|
1807
|
+
factory.createVariableDeclaration(name, undefined, undefined, factory.createConditionalExpression(symbolCheck, create, factory.createVoidZero())),
|
|
1808
|
+
]), 2 /* NodeFlags.Const */));
|
|
1809
|
+
}
|
|
1810
|
+
createSymbolMetadataAccess() {
|
|
1811
|
+
return this.factory.createPropertyAccessExpression(this.factory.createIdentifier('Symbol'), this.factory.createIdentifier('metadata'));
|
|
1812
|
+
}
|
|
1813
|
+
/** `if (metadata) Object.defineProperty(target, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: metadata });` */
|
|
1814
|
+
createSymbolMetadata(target, value) {
|
|
1815
|
+
const factory = this.factory;
|
|
1816
|
+
const descriptor = factory.createObjectLiteral([
|
|
1817
|
+
factory.createPropertyAssignment(factory.createIdentifier('enumerable'), factory.createTrue()),
|
|
1818
|
+
factory.createPropertyAssignment(factory.createIdentifier('configurable'), factory.createTrue()),
|
|
1819
|
+
factory.createPropertyAssignment(factory.createIdentifier('writable'), factory.createTrue()),
|
|
1820
|
+
factory.createPropertyAssignment(factory.createIdentifier('value'), value),
|
|
1821
|
+
], false);
|
|
1822
|
+
const defineProperty = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('Object'), factory.createIdentifier('defineProperty')), [target, this.createSymbolMetadataAccess(), descriptor]);
|
|
1823
|
+
const statement = factory.createIfStatement(value, factory.createExpressionStatement(defineProperty), undefined);
|
|
1824
|
+
this.context.setEmitFlags(statement, 1 /* EmitFlags.SingleLine */);
|
|
1825
|
+
return statement;
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
/** The callee and `this` argument of a call. */
|
|
1829
|
+
class CallBinding {
|
|
1830
|
+
target;
|
|
1831
|
+
thisArg;
|
|
1832
|
+
constructor(target, thisArg) {
|
|
1833
|
+
this.target = target;
|
|
1834
|
+
this.thisArg = thisArg;
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
function shouldBeCapturedInTempVariable(node) {
|
|
1838
|
+
switch (skipParentheses(node).kind) {
|
|
1839
|
+
case 109 /* SyntaxKind.ThisKeyword */:
|
|
1840
|
+
case 8 /* SyntaxKind.NumericLiteral */:
|
|
1841
|
+
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
1842
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
1843
|
+
return false;
|
|
1844
|
+
}
|
|
1845
|
+
return true;
|
|
1846
|
+
}
|
|
1847
|
+
/** `_name`, `_get_name`, `_static_private_name`, `_class` or `_member`, for helper variables of `node`. */
|
|
1848
|
+
function getHelperVariableName(context, node) {
|
|
1849
|
+
const name = getName(node);
|
|
1850
|
+
let declarationName;
|
|
1851
|
+
if (name instanceof Identifier && !context.hasAutoGenerateInfo(name))
|
|
1852
|
+
declarationName = name.text;
|
|
1853
|
+
else if (name instanceof PrivateIdentifier && !context.hasAutoGenerateInfo(name))
|
|
1854
|
+
declarationName = name.text.length > 1 ? name.text.slice(1) : '';
|
|
1855
|
+
else if (name instanceof StringLiteral && isIdentifierText(name.text))
|
|
1856
|
+
declarationName = name.text;
|
|
1857
|
+
else if (isClassLike(node))
|
|
1858
|
+
declarationName = 'class';
|
|
1859
|
+
else
|
|
1860
|
+
declarationName = 'member';
|
|
1861
|
+
if (node.kind === 178 /* SyntaxKind.GetAccessor */)
|
|
1862
|
+
declarationName = 'get_' + declarationName;
|
|
1863
|
+
if (node.kind === 179 /* SyntaxKind.SetAccessor */)
|
|
1864
|
+
declarationName = 'set_' + declarationName;
|
|
1865
|
+
if (name instanceof PrivateIdentifier)
|
|
1866
|
+
declarationName = 'private_' + declarationName;
|
|
1867
|
+
if (isStatic(node))
|
|
1868
|
+
declarationName = 'static_' + declarationName;
|
|
1869
|
+
return '_' + declarationName;
|
|
1870
|
+
}
|
|
1871
|
+
function isStaticPrivateOrAutoAccessor(member) {
|
|
1872
|
+
return ((isPrivateIdentifierClassElementDeclaration(member) || isAutoAccessorPropertyDeclaration(member)) &&
|
|
1873
|
+
hasStaticModifier(member));
|
|
1874
|
+
}
|
|
1875
|
+
function keepsModifier(filter, kind) {
|
|
1876
|
+
switch (filter) {
|
|
1877
|
+
case 0 /* ModifierFilter.NoDecorators */:
|
|
1878
|
+
return kind !== 171 /* SyntaxKind.Decorator */;
|
|
1879
|
+
case 1 /* ModifierFilter.NoExport */:
|
|
1880
|
+
return kind !== 171 /* SyntaxKind.Decorator */ && kind !== 94 /* SyntaxKind.ExportKeyword */;
|
|
1881
|
+
case 2 /* ModifierFilter.StaticOnly */:
|
|
1882
|
+
return kind === 125 /* SyntaxKind.StaticKeyword */;
|
|
1883
|
+
case 3 /* ModifierFilter.AsyncOnly */:
|
|
1884
|
+
return kind === 133 /* SyntaxKind.AsyncKeyword */;
|
|
1885
|
+
case 4 /* ModifierFilter.NoAccessor */:
|
|
1886
|
+
return kind !== 128 /* SyntaxKind.AccessorKeyword */;
|
|
1887
|
+
}
|
|
1888
|
+
return true;
|
|
1889
|
+
}
|
|
1890
|
+
function pushVisited(statements, visited) {
|
|
1891
|
+
if (visited instanceof SyntaxList)
|
|
1892
|
+
appendAll(statements, visited.children);
|
|
1893
|
+
else if (visited !== undefined)
|
|
1894
|
+
statements.push(visited);
|
|
1895
|
+
return true;
|
|
1896
|
+
}
|
|
1897
|
+
function appendAll(target, nodes) {
|
|
1898
|
+
for (let i = 0; i < nodes.length; i++)
|
|
1899
|
+
target.push(nodes[i]);
|
|
1900
|
+
return true;
|
|
1901
|
+
}
|