tsc-ts 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -1
- package/dist/api/compiler/ast-utilities.d.ts +82 -0
- package/dist/api/compiler/ast-utilities.js +462 -0
- package/dist/api/compiler/ast.d.ts +2350 -0
- package/dist/api/compiler/ast.js +11206 -0
- package/dist/api/compiler/astnav.d.ts +37 -0
- package/dist/api/compiler/astnav.js +767 -0
- package/dist/api/compiler/binder-utilities.d.ts +182 -0
- package/dist/api/compiler/binder-utilities.js +1240 -0
- package/dist/api/compiler/binder.d.ts +33 -0
- package/dist/api/compiler/binder.js +2358 -0
- package/dist/api/compiler/character-codes.d.ts +161 -0
- package/dist/api/compiler/character-codes.js +160 -0
- package/dist/api/compiler/checker-calls.d.ts +46 -0
- package/dist/api/compiler/checker-calls.js +1640 -0
- package/dist/api/compiler/checker-classes.d.ts +30 -0
- package/dist/api/compiler/checker-classes.js +582 -0
- package/dist/api/compiler/checker-contextual.d.ts +77 -0
- package/dist/api/compiler/checker-contextual.js +1136 -0
- package/dist/api/compiler/checker-declaration-order.d.ts +12 -0
- package/dist/api/compiler/checker-declaration-order.js +356 -0
- package/dist/api/compiler/checker-declarations.d.ts +33 -0
- package/dist/api/compiler/checker-declarations.js +888 -0
- package/dist/api/compiler/checker-declared-types.d.ts +48 -0
- package/dist/api/compiler/checker-declared-types.js +787 -0
- package/dist/api/compiler/checker-decorators.d.ts +26 -0
- package/dist/api/compiler/checker-decorators.js +562 -0
- package/dist/api/compiler/checker-deprecation.d.ts +33 -0
- package/dist/api/compiler/checker-deprecation.js +315 -0
- package/dist/api/compiler/checker-destructuring.d.ts +34 -0
- package/dist/api/compiler/checker-destructuring.js +584 -0
- package/dist/api/compiler/checker-elaboration.d.ts +15 -0
- package/dist/api/compiler/checker-elaboration.js +290 -0
- package/dist/api/compiler/checker-emit-helpers.d.ts +58 -0
- package/dist/api/compiler/checker-emit-helpers.js +154 -0
- package/dist/api/compiler/checker-emit-resolver.d.ts +75 -0
- package/dist/api/compiler/checker-emit-resolver.js +579 -0
- package/dist/api/compiler/checker-evaluator.d.ts +27 -0
- package/dist/api/compiler/checker-evaluator.js +188 -0
- package/dist/api/compiler/checker-expressions.d.ts +67 -0
- package/dist/api/compiler/checker-expressions.js +1351 -0
- package/dist/api/compiler/checker-features.d.ts +6 -0
- package/dist/api/compiler/checker-features.js +354 -0
- package/dist/api/compiler/checker-flow.d.ts +86 -0
- package/dist/api/compiler/checker-flow.js +169 -0
- package/dist/api/compiler/checker-functions.d.ts +43 -0
- package/dist/api/compiler/checker-functions.js +1002 -0
- package/dist/api/compiler/checker-generated-code.d.ts +25 -0
- package/dist/api/compiler/checker-generated-code.js +168 -0
- package/dist/api/compiler/checker-globals.d.ts +14 -0
- package/dist/api/compiler/checker-globals.js +37 -0
- package/dist/api/compiler/checker-grammar.d.ts +35 -0
- package/dist/api/compiler/checker-grammar.js +2573 -0
- package/dist/api/compiler/checker-heritage.d.ts +28 -0
- package/dist/api/compiler/checker-heritage.js +900 -0
- package/dist/api/compiler/checker-inference.d.ts +179 -0
- package/dist/api/compiler/checker-inference.js +2105 -0
- package/dist/api/compiler/checker-iteration.d.ts +115 -0
- package/dist/api/compiler/checker-iteration.js +857 -0
- package/dist/api/compiler/checker-javascript.d.ts +42 -0
- package/dist/api/compiler/checker-javascript.js +441 -0
- package/dist/api/compiler/checker-jsdoc.d.ts +30 -0
- package/dist/api/compiler/checker-jsdoc.js +320 -0
- package/dist/api/compiler/checker-jsx.d.ts +94 -0
- package/dist/api/compiler/checker-jsx.js +1433 -0
- package/dist/api/compiler/checker-literals.d.ts +6 -0
- package/dist/api/compiler/checker-literals.js +43 -0
- package/dist/api/compiler/checker-members.d.ts +198 -0
- package/dist/api/compiler/checker-members.js +2126 -0
- package/dist/api/compiler/checker-modules.d.ts +85 -0
- package/dist/api/compiler/checker-modules.js +2141 -0
- package/dist/api/compiler/checker-narrowing.d.ts +120 -0
- package/dist/api/compiler/checker-narrowing.js +2797 -0
- package/dist/api/compiler/checker-object-literals.d.ts +14 -0
- package/dist/api/compiler/checker-object-literals.js +479 -0
- package/dist/api/compiler/checker-operators.d.ts +33 -0
- package/dist/api/compiler/checker-operators.js +1040 -0
- package/dist/api/compiler/checker-overloads.d.ts +7 -0
- package/dist/api/compiler/checker-overloads.js +270 -0
- package/dist/api/compiler/checker-property-access.d.ts +34 -0
- package/dist/api/compiler/checker-property-access.js +672 -0
- package/dist/api/compiler/checker-services.d.ts +49 -0
- package/dist/api/compiler/checker-services.js +995 -0
- package/dist/api/compiler/checker-signatures.d.ts +55 -0
- package/dist/api/compiler/checker-signatures.js +788 -0
- package/dist/api/compiler/checker-source-file.d.ts +27 -0
- package/dist/api/compiler/checker-source-file.js +619 -0
- package/dist/api/compiler/checker-statements.d.ts +18 -0
- package/dist/api/compiler/checker-statements.js +226 -0
- package/dist/api/compiler/checker-super.d.ts +13 -0
- package/dist/api/compiler/checker-super.js +241 -0
- package/dist/api/compiler/checker-symbol-types.d.ts +67 -0
- package/dist/api/compiler/checker-symbol-types.js +1885 -0
- package/dist/api/compiler/checker-symbols.d.ts +181 -0
- package/dist/api/compiler/checker-symbols.js +1782 -0
- package/dist/api/compiler/checker-type-factory.d.ts +142 -0
- package/dist/api/compiler/checker-type-factory.js +2501 -0
- package/dist/api/compiler/checker-type-nodes.d.ts +26 -0
- package/dist/api/compiler/checker-type-nodes.js +828 -0
- package/dist/api/compiler/checker-type-operators.d.ts +109 -0
- package/dist/api/compiler/checker-type-operators.js +1842 -0
- package/dist/api/compiler/checker-types.d.ts +1027 -0
- package/dist/api/compiler/checker-types.js +1697 -0
- package/dist/api/compiler/checker-unused.d.ts +19 -0
- package/dist/api/compiler/checker-unused.js +524 -0
- package/dist/api/compiler/checker-utilities.d.ts +33 -0
- package/dist/api/compiler/checker-utilities.js +141 -0
- package/dist/api/compiler/checker.d.ts +491 -0
- package/dist/api/compiler/checker.js +912 -0
- package/dist/api/compiler/command-line.d.ts +32 -0
- package/dist/api/compiler/command-line.js +383 -0
- package/dist/api/compiler/compile-program.d.ts +118 -0
- package/dist/api/compiler/compile-program.js +384 -0
- package/dist/api/compiler/diagnostic-locales.d.ts +22 -0
- package/dist/api/compiler/diagnostic-locales.js +64 -0
- package/dist/api/compiler/diagnostic-messages.d.ts +2166 -0
- package/dist/api/compiler/diagnostic-messages.js +184 -0
- package/dist/api/compiler/diagnostics.d.ts +167 -0
- package/dist/api/compiler/diagnostics.js +820 -0
- package/dist/api/compiler/emitter.d.ts +71 -0
- package/dist/api/compiler/emitter.js +327 -0
- package/dist/api/compiler/file-include.d.ts +117 -0
- package/dist/api/compiler/file-include.js +536 -0
- package/dist/api/compiler/file-loader.d.ts +261 -0
- package/dist/api/compiler/file-loader.js +1257 -0
- package/dist/api/compiler/file-system.d.ts +51 -0
- package/dist/api/compiler/file-system.js +132 -0
- package/dist/api/compiler/flow.d.ts +60 -0
- package/dist/api/compiler/flow.js +45 -0
- package/dist/api/compiler/instantiation.d.ts +74 -0
- package/dist/api/compiler/instantiation.js +799 -0
- package/dist/api/compiler/jsdoc.d.ts +75 -0
- package/dist/api/compiler/jsdoc.js +1229 -0
- package/dist/api/compiler/link-tables.d.ts +36 -0
- package/dist/api/compiler/link-tables.js +83 -0
- package/dist/api/compiler/locale-data.d.ts +24 -0
- package/dist/api/compiler/locale-data.js +183 -0
- package/dist/api/compiler/locale.d.ts +4 -0
- package/dist/api/compiler/locale.js +317 -0
- package/dist/api/compiler/locales/cs-CZ.d.ts +2 -0
- package/dist/api/compiler/locales/cs-CZ.js +3 -0
- package/dist/api/compiler/locales/de-DE.d.ts +2 -0
- package/dist/api/compiler/locales/de-DE.js +3 -0
- package/dist/api/compiler/locales/es-ES.d.ts +2 -0
- package/dist/api/compiler/locales/es-ES.js +3 -0
- package/dist/api/compiler/locales/fr-FR.d.ts +2 -0
- package/dist/api/compiler/locales/fr-FR.js +3 -0
- package/dist/api/compiler/locales/it-IT.d.ts +2 -0
- package/dist/api/compiler/locales/it-IT.js +3 -0
- package/dist/api/compiler/locales/ja-JP.d.ts +2 -0
- package/dist/api/compiler/locales/ja-JP.js +3 -0
- package/dist/api/compiler/locales/ko-KR.d.ts +2 -0
- package/dist/api/compiler/locales/ko-KR.js +3 -0
- package/dist/api/compiler/locales/pl-PL.d.ts +2 -0
- package/dist/api/compiler/locales/pl-PL.js +3 -0
- package/dist/api/compiler/locales/pt-BR.d.ts +2 -0
- package/dist/api/compiler/locales/pt-BR.js +3 -0
- package/dist/api/compiler/locales/ru-RU.d.ts +2 -0
- package/dist/api/compiler/locales/ru-RU.js +3 -0
- package/dist/api/compiler/locales/tr-TR.d.ts +2 -0
- package/dist/api/compiler/locales/tr-TR.js +3 -0
- package/dist/api/compiler/locales/zh-CN.d.ts +2 -0
- package/dist/api/compiler/locales/zh-CN.js +3 -0
- package/dist/api/compiler/locales/zh-TW.d.ts +2 -0
- package/dist/api/compiler/locales/zh-TW.js +3 -0
- package/dist/api/compiler/module-resolution-types.d.ts +83 -0
- package/dist/api/compiler/module-resolution-types.js +176 -0
- package/dist/api/compiler/module-resolution.d.ts +71 -0
- package/dist/api/compiler/module-resolution.js +1598 -0
- package/dist/api/compiler/module-specifiers.d.ts +64 -0
- package/dist/api/compiler/module-specifiers.js +1101 -0
- package/dist/api/compiler/name-resolver.d.ts +43 -0
- package/dist/api/compiler/name-resolver.js +509 -0
- package/dist/api/compiler/node-builder-names.d.ts +32 -0
- package/dist/api/compiler/node-builder-names.js +854 -0
- package/dist/api/compiler/node-builder-pseudo.d.ts +36 -0
- package/dist/api/compiler/node-builder-pseudo.js +744 -0
- package/dist/api/compiler/node-builder-reuse.d.ts +4 -0
- package/dist/api/compiler/node-builder-reuse.js +647 -0
- package/dist/api/compiler/node-builder.d.ts +270 -0
- package/dist/api/compiler/node-builder.js +2645 -0
- package/dist/api/compiler/option-declarations.d.ts +90 -0
- package/dist/api/compiler/option-declarations.js +1460 -0
- package/dist/api/compiler/options.d.ts +289 -0
- package/dist/api/compiler/options.js +1197 -0
- package/dist/api/compiler/output-paths.d.ts +42 -0
- package/dist/api/compiler/output-paths.js +195 -0
- package/dist/api/compiler/package-json.d.ts +175 -0
- package/dist/api/compiler/package-json.js +1015 -0
- package/dist/api/compiler/parallel-parse.d.ts +219 -0
- package/dist/api/compiler/parallel-parse.js +537 -0
- package/dist/api/compiler/parser.d.ts +587 -0
- package/dist/api/compiler/parser.js +6407 -0
- package/dist/api/compiler/path.d.ts +91 -0
- package/dist/api/compiler/path.js +705 -0
- package/dist/api/compiler/printer/async-helpers.d.ts +22 -0
- package/dist/api/compiler/printer/async-helpers.js +91 -0
- package/dist/api/compiler/printer/auto-generate.d.ts +13 -0
- package/dist/api/compiler/printer/auto-generate.js +20 -0
- package/dist/api/compiler/printer/decorator-helpers.d.ts +24 -0
- package/dist/api/compiler/printer/decorator-helpers.js +118 -0
- package/dist/api/compiler/printer/emit-context.d.ts +154 -0
- package/dist/api/compiler/printer/emit-context.js +576 -0
- package/dist/api/compiler/printer/emit-flags.d.ts +60 -0
- package/dist/api/compiler/printer/emit-flags.js +2 -0
- package/dist/api/compiler/printer/factory-base.d.ts +171 -0
- package/dist/api/compiler/printer/factory-base.js +1505 -0
- package/dist/api/compiler/printer/factory.d.ts +147 -0
- package/dist/api/compiler/printer/factory.js +542 -0
- package/dist/api/compiler/printer/helpers.d.ts +27 -0
- package/dist/api/compiler/printer/helpers.js +164 -0
- package/dist/api/compiler/printer/name-generator.d.ts +41 -0
- package/dist/api/compiler/printer/name-generator.js +283 -0
- package/dist/api/compiler/printer/printer.d.ts +411 -0
- package/dist/api/compiler/printer/printer.js +4517 -0
- package/dist/api/compiler/printer/text-writer.d.ts +46 -0
- package/dist/api/compiler/printer/text-writer.js +172 -0
- package/dist/api/compiler/printer/utilities.d.ts +82 -0
- package/dist/api/compiler/printer/utilities.js +817 -0
- package/dist/api/compiler/program-checker.d.ts +156 -0
- package/dist/api/compiler/program-checker.js +526 -0
- package/dist/api/compiler/program-utilities.d.ts +52 -0
- package/dist/api/compiler/program-utilities.js +365 -0
- package/dist/api/compiler/program.d.ts +180 -0
- package/dist/api/compiler/program.js +1011 -0
- package/dist/api/compiler/pseudo-bigint.d.ts +5 -0
- package/dist/api/compiler/pseudo-bigint.js +61 -0
- package/dist/api/compiler/regexp-checker.d.ts +38 -0
- package/dist/api/compiler/regexp-checker.js +942 -0
- package/dist/api/compiler/relations.d.ts +263 -0
- package/dist/api/compiler/relations.js +4002 -0
- package/dist/api/compiler/reparser.d.ts +48 -0
- package/dist/api/compiler/reparser.js +1323 -0
- package/dist/api/compiler/scanner.d.ts +256 -0
- package/dist/api/compiler/scanner.js +2853 -0
- package/dist/api/compiler/side-state.d.ts +16 -0
- package/dist/api/compiler/side-state.js +89 -0
- package/dist/api/compiler/sourcemap.d.ts +55 -0
- package/dist/api/compiler/sourcemap.js +340 -0
- package/dist/api/compiler/spelling.d.ts +14 -0
- package/dist/api/compiler/spelling.js +128 -0
- package/dist/api/compiler/symbol-accessibility.d.ts +57 -0
- package/dist/api/compiler/symbol-accessibility.js +894 -0
- package/dist/api/compiler/symbol.d.ts +240 -0
- package/dist/api/compiler/symbol.js +228 -0
- package/dist/api/compiler/symlinks.d.ts +32 -0
- package/dist/api/compiler/symlinks.js +114 -0
- package/dist/api/compiler/syntax-kind.d.ts +389 -0
- package/dist/api/compiler/syntax-kind.js +2 -0
- package/dist/api/compiler/timeline.d.ts +9 -0
- package/dist/api/compiler/timeline.js +54 -0
- package/dist/api/compiler/transformers/alias-references.d.ts +39 -0
- package/dist/api/compiler/transformers/alias-references.js +676 -0
- package/dist/api/compiler/transformers/async-utilities.d.ts +51 -0
- package/dist/api/compiler/transformers/async-utilities.js +260 -0
- package/dist/api/compiler/transformers/async.d.ts +53 -0
- package/dist/api/compiler/transformers/async.js +645 -0
- package/dist/api/compiler/transformers/class-fields.d.ts +206 -0
- package/dist/api/compiler/transformers/class-fields.js +2418 -0
- package/dist/api/compiler/transformers/class-utilities.d.ts +46 -0
- package/dist/api/compiler/transformers/class-utilities.js +261 -0
- package/dist/api/compiler/transformers/commonjs-module.d.ts +103 -0
- package/dist/api/compiler/transformers/commonjs-module.js +1180 -0
- package/dist/api/compiler/transformers/const-enum-inliner.d.ts +11 -0
- package/dist/api/compiler/transformers/const-enum-inliner.js +36 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.d.ts +52 -0
- package/dist/api/compiler/transformers/declarations-diagnostics.js +538 -0
- package/dist/api/compiler/transformers/declarations-pseudo.d.ts +160 -0
- package/dist/api/compiler/transformers/declarations-pseudo.js +797 -0
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +152 -0
- package/dist/api/compiler/transformers/declarations-resolver.js +35 -0
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +119 -0
- package/dist/api/compiler/transformers/declarations-syntactic.js +1582 -0
- package/dist/api/compiler/transformers/declarations-tracker.d.ts +46 -0
- package/dist/api/compiler/transformers/declarations-tracker.js +197 -0
- package/dist/api/compiler/transformers/declarations.d.ts +175 -0
- package/dist/api/compiler/transformers/declarations.js +2380 -0
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +54 -0
- package/dist/api/compiler/transformers/decorator-metadata.js +554 -0
- package/dist/api/compiler/transformers/decorator-utilities.d.ts +38 -0
- package/dist/api/compiler/transformers/decorator-utilities.js +238 -0
- package/dist/api/compiler/transformers/destructuring.d.ts +25 -0
- package/dist/api/compiler/transformers/destructuring.js +626 -0
- package/dist/api/compiler/transformers/downlevel.d.ts +6 -0
- package/dist/api/compiler/transformers/downlevel.js +45 -0
- package/dist/api/compiler/transformers/emit-resolver.d.ts +61 -0
- package/dist/api/compiler/transformers/emit-resolver.js +197 -0
- package/dist/api/compiler/transformers/es-decorators.d.ts +118 -0
- package/dist/api/compiler/transformers/es-decorators.js +1901 -0
- package/dist/api/compiler/transformers/exponentiation.d.ts +11 -0
- package/dist/api/compiler/transformers/exponentiation.js +76 -0
- package/dist/api/compiler/transformers/external-module-info.d.ts +35 -0
- package/dist/api/compiler/transformers/external-module-info.js +351 -0
- package/dist/api/compiler/transformers/for-await.d.ts +43 -0
- package/dist/api/compiler/transformers/for-await.js +469 -0
- package/dist/api/compiler/transformers/import-elision.d.ts +16 -0
- package/dist/api/compiler/transformers/import-elision.js +124 -0
- package/dist/api/compiler/transformers/jsx-entities.d.ts +1 -0
- package/dist/api/compiler/transformers/jsx-entities.js +256 -0
- package/dist/api/compiler/transformers/jsx.d.ts +71 -0
- package/dist/api/compiler/transformers/jsx.js +700 -0
- package/dist/api/compiler/transformers/legacy-decorators.d.ts +56 -0
- package/dist/api/compiler/transformers/legacy-decorators.js +564 -0
- package/dist/api/compiler/transformers/logical-assignment.d.ts +14 -0
- package/dist/api/compiler/transformers/logical-assignment.js +62 -0
- package/dist/api/compiler/transformers/module-utilities.d.ts +9 -0
- package/dist/api/compiler/transformers/module-utilities.js +36 -0
- package/dist/api/compiler/transformers/module.d.ts +49 -0
- package/dist/api/compiler/transformers/module.js +296 -0
- package/dist/api/compiler/transformers/named-evaluation.d.ts +26 -0
- package/dist/api/compiler/transformers/named-evaluation.js +266 -0
- package/dist/api/compiler/transformers/nullish-coalescing.d.ts +9 -0
- package/dist/api/compiler/transformers/nullish-coalescing.js +26 -0
- package/dist/api/compiler/transformers/object-rest-spread.d.ts +34 -0
- package/dist/api/compiler/transformers/object-rest-spread.js +411 -0
- package/dist/api/compiler/transformers/optional-catch.d.ts +9 -0
- package/dist/api/compiler/transformers/optional-catch.js +20 -0
- package/dist/api/compiler/transformers/optional-chain.d.ts +14 -0
- package/dist/api/compiler/transformers/optional-chain.js +188 -0
- package/dist/api/compiler/transformers/reference-resolver.d.ts +128 -0
- package/dist/api/compiler/transformers/reference-resolver.js +1155 -0
- package/dist/api/compiler/transformers/runtime-syntax.d.ts +71 -0
- package/dist/api/compiler/transformers/runtime-syntax.js +753 -0
- package/dist/api/compiler/transformers/subtree-facts.d.ts +9 -0
- package/dist/api/compiler/transformers/subtree-facts.js +203 -0
- package/dist/api/compiler/transformers/syntax-facts.d.ts +51 -0
- package/dist/api/compiler/transformers/syntax-facts.js +254 -0
- package/dist/api/compiler/transformers/tagged-template.d.ts +17 -0
- package/dist/api/compiler/transformers/tagged-template.js +148 -0
- package/dist/api/compiler/transformers/transformer.d.ts +17 -0
- package/dist/api/compiler/transformers/transformer.js +54 -0
- package/dist/api/compiler/transformers/type-eraser.d.ts +21 -0
- package/dist/api/compiler/transformers/type-eraser.js +346 -0
- package/dist/api/compiler/transformers/type-serialization.d.ts +20 -0
- package/dist/api/compiler/transformers/type-serialization.js +347 -0
- package/dist/api/compiler/transformers/using.d.ts +56 -0
- package/dist/api/compiler/transformers/using.js +453 -0
- package/dist/api/compiler/transformers/utilities.d.ts +50 -0
- package/dist/api/compiler/transformers/utilities.js +347 -0
- package/dist/api/compiler/transformers/visitor-base.d.ts +6 -0
- package/dist/api/compiler/transformers/visitor-base.js +817 -0
- package/dist/api/compiler/transformers/visitor-hooks.d.ts +29 -0
- package/dist/api/compiler/transformers/visitor-hooks.js +189 -0
- package/dist/api/compiler/tsconfig.d.ts +177 -0
- package/dist/api/compiler/tsconfig.js +1311 -0
- package/dist/api/compiler/type-printer.d.ts +15 -0
- package/dist/api/compiler/type-printer.js +74 -0
- package/dist/api/compiler/types.d.ts +87 -0
- package/dist/api/compiler/types.js +23 -0
- package/dist/api/compiler/unicode-identifiers.d.ts +2 -0
- package/dist/api/compiler/unicode-identifiers.js +209 -0
- package/dist/api/compiler/unicode-properties.d.ts +8 -0
- package/dist/api/compiler/unicode-properties.js +531 -0
- package/dist/api/compiler/vfs-match.d.ts +24 -0
- package/dist/api/compiler/vfs-match.js +587 -0
- package/dist/api/library/ast.d.ts +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 +12862 -0
- package/src/compiler/astnav.ts +799 -0
- package/src/compiler/binder-utilities.ts +1392 -0
- package/src/compiler/binder.ts +2703 -0
- package/src/compiler/build-info.ts +1197 -0
- package/src/compiler/character-codes.ts +323 -0
- package/src/compiler/checker-calls.ts +2155 -0
- package/src/compiler/checker-classes.ts +706 -0
- package/src/compiler/checker-contextual.ts +1457 -0
- package/src/compiler/checker-declaration-order.ts +438 -0
- package/src/compiler/checker-declarations.ts +1194 -0
- package/src/compiler/checker-declared-types.ts +919 -0
- package/src/compiler/checker-decorators.ts +694 -0
- package/src/compiler/checker-deprecation.ts +359 -0
- package/src/compiler/checker-destructuring.ts +805 -0
- package/src/compiler/checker-elaboration.ts +477 -0
- package/src/compiler/checker-emit-helpers.ts +224 -0
- package/src/compiler/checker-emit-resolver.ts +769 -0
- package/src/compiler/checker-evaluator.ts +243 -0
- package/src/compiler/checker-expressions.ts +1831 -0
- package/src/compiler/checker-features.ts +361 -0
- package/src/compiler/checker-flow.ts +394 -0
- package/src/compiler/checker-functions.ts +1296 -0
- package/src/compiler/checker-generated-code.ts +227 -0
- package/src/compiler/checker-globals.ts +52 -0
- package/src/compiler/checker-grammar.ts +3584 -0
- package/src/compiler/checker-heritage.ts +1233 -0
- package/src/compiler/checker-inference.ts +2576 -0
- package/src/compiler/checker-iteration.ts +1206 -0
- package/src/compiler/checker-javascript.ts +502 -0
- package/src/compiler/checker-jsdoc.ts +360 -0
- package/src/compiler/checker-jsx.ts +1924 -0
- package/src/compiler/checker-literals.ts +61 -0
- package/src/compiler/checker-members.ts +2436 -0
- package/src/compiler/checker-modules.ts +2886 -0
- package/src/compiler/checker-narrowing.ts +3230 -0
- package/src/compiler/checker-object-literals.ts +575 -0
- package/src/compiler/checker-operators.ts +1422 -0
- package/src/compiler/checker-overloads.ts +328 -0
- package/src/compiler/checker-property-access.ts +906 -0
- package/src/compiler/checker-services.ts +1149 -0
- package/src/compiler/checker-signatures.ts +1032 -0
- package/src/compiler/checker-source-file.ts +732 -0
- package/src/compiler/checker-statements.ts +292 -0
- package/src/compiler/checker-super.ts +261 -0
- package/src/compiler/checker-symbol-types.ts +2107 -0
- package/src/compiler/checker-symbols.ts +2150 -0
- package/src/compiler/checker-type-factory.ts +2579 -0
- package/src/compiler/checker-type-nodes.ts +1033 -0
- package/src/compiler/checker-type-operators.ts +2502 -0
- package/src/compiler/checker-types.ts +2340 -0
- package/src/compiler/checker-unused.ts +642 -0
- package/src/compiler/checker-utilities.ts +161 -0
- package/src/compiler/checker.ts +1116 -0
- package/src/compiler/command-line.ts +436 -0
- package/src/compiler/compile-program.ts +439 -0
- package/src/compiler/decoder.ts +1209 -0
- package/src/compiler/diagnostic-locales.ts +86 -0
- package/src/compiler/diagnostic-messages.ts +2349 -0
- package/src/compiler/diagnostics.ts +897 -0
- package/src/compiler/emitter.ts +434 -0
- package/src/compiler/encoder.ts +1945 -0
- package/src/compiler/file-include.ts +673 -0
- package/src/compiler/file-loader.ts +1528 -0
- package/src/compiler/file-system.ts +143 -0
- package/src/compiler/flow.ts +89 -0
- package/src/compiler/help.ts +473 -0
- package/src/compiler/incremental.ts +2784 -0
- package/src/compiler/init.ts +141 -0
- package/src/compiler/instantiation.ts +894 -0
- package/src/compiler/jsdoc.ts +1386 -0
- package/src/compiler/link-tables.ts +98 -0
- package/src/compiler/locale-data.ts +203 -0
- package/src/compiler/locale.ts +307 -0
- package/src/compiler/locales/cs-CZ.ts +5 -0
- package/src/compiler/locales/de-DE.ts +5 -0
- package/src/compiler/locales/es-ES.ts +5 -0
- package/src/compiler/locales/fr-FR.ts +5 -0
- package/src/compiler/locales/it-IT.ts +5 -0
- package/src/compiler/locales/ja-JP.ts +5 -0
- package/src/compiler/locales/ko-KR.ts +5 -0
- package/src/compiler/locales/pl-PL.ts +5 -0
- package/src/compiler/locales/pt-BR.ts +5 -0
- package/src/compiler/locales/ru-RU.ts +5 -0
- package/src/compiler/locales/tr-TR.ts +5 -0
- package/src/compiler/locales/zh-CN.ts +5 -0
- package/src/compiler/locales/zh-TW.ts +5 -0
- package/src/compiler/module-resolution-types.ts +243 -0
- package/src/compiler/module-resolution.ts +2072 -0
- package/src/compiler/module-specifiers.ts +1491 -0
- package/src/compiler/name-resolver.ts +646 -0
- package/src/compiler/node-builder-names.ts +1069 -0
- package/src/compiler/node-builder-pseudo.ts +892 -0
- package/src/compiler/node-builder-reuse.ts +764 -0
- package/src/compiler/node-builder.ts +3425 -0
- package/src/compiler/option-declarations.ts +1560 -0
- package/src/compiler/options.ts +1576 -0
- package/src/compiler/output-paths.ts +334 -0
- package/src/compiler/package-json.ts +1083 -0
- package/src/compiler/parallel-check.ts +1951 -0
- package/src/compiler/parallel-parse.ts +590 -0
- package/src/compiler/parse-thread.ts +140 -0
- package/src/compiler/parser.ts +7716 -0
- package/src/compiler/path.ts +717 -0
- package/src/compiler/printer/async-helpers.ts +183 -0
- package/src/compiler/printer/auto-generate.ts +27 -0
- package/src/compiler/printer/decorator-helpers.ts +218 -0
- package/src/compiler/printer/emit-context.ts +679 -0
- package/src/compiler/printer/emit-flags.ts +64 -0
- package/src/compiler/printer/factory-base.ts +2577 -0
- package/src/compiler/printer/factory.ts +764 -0
- package/src/compiler/printer/helpers.ts +291 -0
- package/src/compiler/printer/name-generator.ts +372 -0
- package/src/compiler/printer/printer.ts +5072 -0
- package/src/compiler/printer/text-writer.ts +183 -0
- package/src/compiler/printer/utilities.ts +884 -0
- package/src/compiler/program-checker.ts +592 -0
- package/src/compiler/program-utilities.ts +435 -0
- package/src/compiler/program.ts +1419 -0
- package/src/compiler/pseudo-bigint.ts +62 -0
- package/src/compiler/regexp-checker.ts +1142 -0
- package/src/compiler/relations.ts +5149 -0
- package/src/compiler/reparser.ts +1566 -0
- package/src/compiler/scanner.ts +2951 -0
- package/src/compiler/show-config.ts +239 -0
- package/src/compiler/side-state.ts +125 -0
- package/src/compiler/sourcemap.ts +366 -0
- package/src/compiler/spelling.ts +122 -0
- package/src/compiler/symbol-accessibility.ts +1071 -0
- package/src/compiler/symbol.ts +439 -0
- package/src/compiler/symlinks.ts +137 -0
- package/src/compiler/syntax-kind.ts +391 -0
- package/src/compiler/thread-entry.ts +191 -0
- package/src/compiler/timeline.ts +53 -0
- package/src/compiler/transformers/alias-references.ts +757 -0
- package/src/compiler/transformers/async-utilities.ts +335 -0
- package/src/compiler/transformers/async.ts +838 -0
- package/src/compiler/transformers/class-fields.ts +2967 -0
- package/src/compiler/transformers/class-utilities.ts +324 -0
- package/src/compiler/transformers/commonjs-module.ts +1621 -0
- package/src/compiler/transformers/const-enum-inliner.ts +50 -0
- package/src/compiler/transformers/declarations-diagnostics.ts +832 -0
- package/src/compiler/transformers/declarations-pseudo.ts +966 -0
- package/src/compiler/transformers/declarations-resolver.ts +249 -0
- package/src/compiler/transformers/declarations-syntactic.ts +1859 -0
- package/src/compiler/transformers/declarations-tracker.ts +269 -0
- package/src/compiler/transformers/declarations.ts +3120 -0
- package/src/compiler/transformers/decorator-metadata.ts +697 -0
- package/src/compiler/transformers/decorator-utilities.ts +283 -0
- package/src/compiler/transformers/destructuring.ts +708 -0
- package/src/compiler/transformers/downlevel.ts +50 -0
- package/src/compiler/transformers/emit-resolver.ts +258 -0
- package/src/compiler/transformers/es-decorators.ts +2682 -0
- package/src/compiler/transformers/exponentiation.ts +80 -0
- package/src/compiler/transformers/external-module-info.ts +412 -0
- package/src/compiler/transformers/for-await.ts +687 -0
- package/src/compiler/transformers/import-elision.ts +152 -0
- package/src/compiler/transformers/jsx-entities.ts +256 -0
- package/src/compiler/transformers/jsx.ts +824 -0
- package/src/compiler/transformers/legacy-decorators.ts +726 -0
- package/src/compiler/transformers/logical-assignment.ts +75 -0
- package/src/compiler/transformers/module-utilities.ts +42 -0
- package/src/compiler/transformers/module.ts +474 -0
- package/src/compiler/transformers/named-evaluation.ts +389 -0
- package/src/compiler/transformers/nullish-coalescing.ts +35 -0
- package/src/compiler/transformers/object-rest-spread.ts +577 -0
- package/src/compiler/transformers/optional-catch.ts +29 -0
- package/src/compiler/transformers/optional-chain.ts +246 -0
- package/src/compiler/transformers/reference-resolver.ts +1201 -0
- package/src/compiler/transformers/runtime-syntax.ts +942 -0
- package/src/compiler/transformers/subtree-facts.ts +245 -0
- package/src/compiler/transformers/syntax-facts.ts +353 -0
- package/src/compiler/transformers/tagged-template.ts +167 -0
- package/src/compiler/transformers/transformer.ts +56 -0
- package/src/compiler/transformers/type-eraser.ts +520 -0
- package/src/compiler/transformers/type-serialization.ts +374 -0
- package/src/compiler/transformers/using.ts +613 -0
- package/src/compiler/transformers/utilities.ts +419 -0
- package/src/compiler/transformers/visitor-base.ts +1601 -0
- package/src/compiler/transformers/visitor-hooks.ts +252 -0
- package/src/compiler/tsc-build.ts +1418 -0
- package/src/compiler/tsc-cli.ts +666 -0
- package/src/compiler/tsc-compile.ts +437 -0
- package/src/compiler/tsc-watch.ts +854 -0
- package/src/compiler/tsconfig.ts +1574 -0
- package/src/compiler/type-printer.ts +110 -0
- package/src/compiler/types.ts +115 -0
- package/src/compiler/unicode-identifiers.ts +212 -0
- package/src/compiler/unicode-properties.ts +537 -0
- package/src/compiler/vfs-match.ts +597 -0
- package/src/compiler/xxh3.ts +650 -0
- package/src/library/ast.generated.ts +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,1180 @@
|
|
|
1
|
+
// CommonJS module output: imports become `require` calls, exports assignments to `exports`.
|
|
2
|
+
import { ArrowFunction, BinaryExpression, BindingPattern, Block, CallExpression, CaseBlock, CaseOrDefaultClause, CatchClause, ClassDeclaration, ClassExpression, DoStatement, ExportAssignment, ExportDeclaration, ExportSpecifier, ExpressionStatement, ExternalModuleReference, ForInOrOfStatement, ForStatement, FunctionDeclaration, FunctionExpression, Identifier, IfStatement, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportSpecifier, LabeledStatement, NamedExports, NamespaceExport, NodeList, NodeVisitor, ObjectLiteralExpression, ArrayLiteralExpression, ParenthesizedExpression, PartiallyEmittedExpression, PostfixUnaryExpression, PrefixUnaryExpression, PropertyAssignment, ShorthandPropertyAssignment, SourceFile, SpreadAssignment, SpreadElement, StringLiteral, SwitchStatement, TaggedTemplateExpression, TemplateExpression, TemplateHead, TemplateSpan, TemplateTail, TryStatement, VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement, EmptyStatement, getElements, getName, } from '../ast.js';
|
|
3
|
+
import { getExternalModuleName, isImportCall, isInJSFile, isRequireCall } from '../ast-utilities.js';
|
|
4
|
+
import { isAssignmentExpression, isDestructuringAssignment } from '../binder-utilities.js';
|
|
5
|
+
import { JsxEmit, ModuleKind, ScriptTarget, getEmitModuleKind, getEmitScriptTarget, } from '../options.js';
|
|
6
|
+
import { isPrologueDirective } from '../printer/utilities.js';
|
|
7
|
+
import { fileExtensionIsOneOf } from '../path.js';
|
|
8
|
+
import { AssignmentFactory, convertVariableDeclarationToAssignment, flattenDestructuringAssignment, isSimpleCopiableExpression, } from './destructuring.js';
|
|
9
|
+
import { collectExternalModuleInfo, createExternalHelpersImportDeclarationIfNeeded, getImportNeedsImportDefaultHelper, getImportNeedsImportStarHelper, getNamespaceDeclarationNode, isDefaultImport, isEffectiveExternalModule, moduleExportNameText, } from './external-module-info.js';
|
|
10
|
+
import { Transformer } from './transformer.js';
|
|
11
|
+
import { hasSyntacticModifier, isExternalModule, isIdentifierReference, singleOrMany } from './utilities.js';
|
|
12
|
+
import { VisitorBase } from './visitor-base.js';
|
|
13
|
+
import { createRequireCallArguments, rewriteModuleSpecifier } from './module-utilities.js';
|
|
14
|
+
const exportDefault = 32 /* ModifierFlags.Export */ | 2048 /* ModifierFlags.Default */;
|
|
15
|
+
const supportedJSExtensions = ['.js', '.jsx', '.mjs', '.cjs'];
|
|
16
|
+
/** Visits children in one of the transform's modes. */
|
|
17
|
+
class ModeVisitor extends VisitorBase {
|
|
18
|
+
owner;
|
|
19
|
+
mode;
|
|
20
|
+
constructor(owner, mode) {
|
|
21
|
+
super(owner.context);
|
|
22
|
+
this.owner = owner;
|
|
23
|
+
this.mode = mode;
|
|
24
|
+
}
|
|
25
|
+
visit(node) {
|
|
26
|
+
return this.owner.visitInMode(this.mode, node);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** Assigns flattened destructuring targets that are exported to `exports.x` as well. */
|
|
30
|
+
class ExportAssignments extends AssignmentFactory {
|
|
31
|
+
owner;
|
|
32
|
+
constructor(owner) {
|
|
33
|
+
super();
|
|
34
|
+
this.owner = owner;
|
|
35
|
+
}
|
|
36
|
+
createAssignment(name, value, pos, end) {
|
|
37
|
+
return this.owner.createAllExportExpressions(name, value, pos, end);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class CommonJSModuleTransformer extends Transformer {
|
|
41
|
+
options;
|
|
42
|
+
resolver;
|
|
43
|
+
formats;
|
|
44
|
+
moduleKind;
|
|
45
|
+
languageVersion;
|
|
46
|
+
topLevel;
|
|
47
|
+
topLevelNested;
|
|
48
|
+
discarded;
|
|
49
|
+
exportAssignments;
|
|
50
|
+
currentSourceFile;
|
|
51
|
+
info;
|
|
52
|
+
parentNode;
|
|
53
|
+
currentNode;
|
|
54
|
+
constructor(context, options, resolver, formats) {
|
|
55
|
+
super(context);
|
|
56
|
+
this.options = options;
|
|
57
|
+
this.resolver = resolver;
|
|
58
|
+
this.formats = formats;
|
|
59
|
+
this.moduleKind = getEmitModuleKind(options);
|
|
60
|
+
this.languageVersion = getEmitScriptTarget(options);
|
|
61
|
+
this.topLevel = new ModeVisitor(this, 0 /* VisitMode.TopLevel */);
|
|
62
|
+
this.topLevelNested = new ModeVisitor(this, 1 /* VisitMode.TopLevelNested */);
|
|
63
|
+
this.discarded = new ModeVisitor(this, 2 /* VisitMode.DiscardedValue */);
|
|
64
|
+
this.exportAssignments = new ExportAssignments(this);
|
|
65
|
+
this.currentSourceFile = undefined;
|
|
66
|
+
this.info = undefined;
|
|
67
|
+
this.parentNode = undefined;
|
|
68
|
+
this.currentNode = undefined;
|
|
69
|
+
}
|
|
70
|
+
moduleInfo() {
|
|
71
|
+
return this.info;
|
|
72
|
+
}
|
|
73
|
+
// Visitors
|
|
74
|
+
visit(node) {
|
|
75
|
+
const grandparent = this.pushNode(node);
|
|
76
|
+
const result = this.visitNoStack(node, false);
|
|
77
|
+
this.popNode(grandparent);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
visitInMode(mode, node) {
|
|
81
|
+
if (mode === 0 /* VisitMode.TopLevel */)
|
|
82
|
+
return this.visitTopLevel(node);
|
|
83
|
+
const grandparent = this.pushNode(node);
|
|
84
|
+
const result = mode === 1 /* VisitMode.TopLevelNested */ ? this.visitTopLevelNestedNoStack(node) : this.visitNoStack(node, true);
|
|
85
|
+
this.popNode(grandparent);
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
pushNode(node) {
|
|
89
|
+
const grandparent = this.parentNode;
|
|
90
|
+
this.parentNode = this.currentNode;
|
|
91
|
+
this.currentNode = node;
|
|
92
|
+
return grandparent;
|
|
93
|
+
}
|
|
94
|
+
popNode(grandparent) {
|
|
95
|
+
this.currentNode = this.parentNode;
|
|
96
|
+
this.parentNode = grandparent;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
visitTopLevel(node) {
|
|
100
|
+
const grandparent = this.pushNode(node);
|
|
101
|
+
let result;
|
|
102
|
+
if (node instanceof ImportDeclaration)
|
|
103
|
+
result = this.visitTopLevelImportDeclaration(node);
|
|
104
|
+
else if (node instanceof ImportEqualsDeclaration)
|
|
105
|
+
result = this.visitTopLevelImportEqualsDeclaration(node);
|
|
106
|
+
else if (node instanceof ExportDeclaration)
|
|
107
|
+
result = this.visitTopLevelExportDeclaration(node);
|
|
108
|
+
else if (node instanceof ExportAssignment)
|
|
109
|
+
result = this.visitTopLevelExportAssignment(node);
|
|
110
|
+
else if (node instanceof FunctionDeclaration)
|
|
111
|
+
result = this.visitTopLevelFunctionDeclaration(node);
|
|
112
|
+
else if (node instanceof ClassDeclaration)
|
|
113
|
+
result = this.visitTopLevelClassDeclaration(node);
|
|
114
|
+
else if (node instanceof VariableStatement)
|
|
115
|
+
result = this.visitTopLevelVariableStatement(node);
|
|
116
|
+
else
|
|
117
|
+
result = this.visitTopLevelNestedNoStack(node);
|
|
118
|
+
this.popNode(grandparent);
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
visitTopLevelNestedNoStack(node) {
|
|
122
|
+
const factory = this.factory;
|
|
123
|
+
const nested = this.topLevelNested;
|
|
124
|
+
if (node instanceof VariableStatement)
|
|
125
|
+
return this.visitTopLevelVariableStatement(node);
|
|
126
|
+
if (node instanceof ForStatement)
|
|
127
|
+
return this.visitTopLevelNestedForStatement(node);
|
|
128
|
+
if (node instanceof ForInOrOfStatement)
|
|
129
|
+
return this.visitTopLevelNestedForInOrOfStatement(node);
|
|
130
|
+
if (node instanceof DoStatement)
|
|
131
|
+
return factory.updateDoStatement(node, nested.visitIterationBody(node.statement), this.visitNode(node.expression));
|
|
132
|
+
if (node instanceof WhileStatement)
|
|
133
|
+
return factory.updateWhileStatement(node, this.visitNode(node.expression), nested.visitIterationBody(node.statement));
|
|
134
|
+
if (node instanceof LabeledStatement) {
|
|
135
|
+
const statement = nested.visitStatement(node.statement);
|
|
136
|
+
return factory.updateLabeledStatement(node, node.label, statement !== undefined ? statement : factory.created(new EmptyStatement()));
|
|
137
|
+
}
|
|
138
|
+
if (node instanceof WithStatement)
|
|
139
|
+
return factory.updateWithStatement(node, this.visitNode(node.expression), nested.visitStatement(node.statement));
|
|
140
|
+
if (node instanceof IfStatement) {
|
|
141
|
+
const thenStatement = nested.visitStatement(node.thenStatement);
|
|
142
|
+
return factory.updateIfStatement(node, this.visitNode(node.expression), thenStatement !== undefined ? thenStatement : factory.createBlock([], false), nested.visitStatement(node.elseStatement));
|
|
143
|
+
}
|
|
144
|
+
if (node instanceof SwitchStatement) {
|
|
145
|
+
const caseBlock = nested.visitNode(node.caseBlock);
|
|
146
|
+
return factory.updateSwitchStatement(node, this.visitNode(node.expression), caseBlock instanceof CaseBlock ? caseBlock : node.caseBlock);
|
|
147
|
+
}
|
|
148
|
+
if (node instanceof CaseBlock || node instanceof TryStatement || node instanceof Block)
|
|
149
|
+
return nested.visitEachChild(node);
|
|
150
|
+
if (node instanceof CaseOrDefaultClause)
|
|
151
|
+
return factory.updateCaseOrDefaultClause(node, this.visitNode(node.expression), nested.visitNodes(node.statements));
|
|
152
|
+
if (node instanceof CatchClause) {
|
|
153
|
+
const block = nested.visitNode(node.block);
|
|
154
|
+
return factory.updateCatchClause(node, node.variableDeclaration, block instanceof Block ? block : node.block);
|
|
155
|
+
}
|
|
156
|
+
return this.visitNoStack(node, false);
|
|
157
|
+
}
|
|
158
|
+
/** Visits a node other than a top-level statement; `discarded` if its value is unused. */
|
|
159
|
+
visitNoStack(node, discarded) {
|
|
160
|
+
if (node instanceof SourceFile)
|
|
161
|
+
return this.visitSourceFile(node);
|
|
162
|
+
if (node instanceof ForStatement)
|
|
163
|
+
return this.factory.updateForStatement(node, this.discarded.visitNode(node.initializer), this.visitNode(node.condition), this.discarded.visitNode(node.incrementor), this.topLevelNested.visitIterationBody(node.statement));
|
|
164
|
+
if (node instanceof ForInOrOfStatement)
|
|
165
|
+
return this.factory.updateForInOrOfStatement(node, node.awaitModifier, this.discarded.visitNode(node.initializer), this.visitNode(node.expression), this.topLevelNested.visitIterationBody(node.statement));
|
|
166
|
+
if (node instanceof ExpressionStatement || node instanceof VoidExpression)
|
|
167
|
+
return this.discarded.visitEachChild(node);
|
|
168
|
+
if (node instanceof ParenthesizedExpression)
|
|
169
|
+
return this.factory.updateParenthesizedExpression(node, (discarded ? this.discarded.visitNode(node.expression) : this.visitNode(node.expression)));
|
|
170
|
+
if (node instanceof PartiallyEmittedExpression)
|
|
171
|
+
return this.factory.updatePartiallyEmittedExpression(node, (discarded ? this.discarded.visitNode(node.expression) : this.visitNode(node.expression)));
|
|
172
|
+
if (node instanceof CallExpression)
|
|
173
|
+
return this.visitCallExpression(node);
|
|
174
|
+
if (node instanceof TaggedTemplateExpression)
|
|
175
|
+
return this.visitTaggedTemplateExpression(node);
|
|
176
|
+
if (node instanceof BinaryExpression)
|
|
177
|
+
return this.visitBinaryExpression(node, discarded);
|
|
178
|
+
if (node instanceof PrefixUnaryExpression)
|
|
179
|
+
return this.visitPrefixUnaryExpression(node);
|
|
180
|
+
if (node instanceof PostfixUnaryExpression)
|
|
181
|
+
return this.visitPostfixUnaryExpression(node, discarded);
|
|
182
|
+
if (node instanceof ShorthandPropertyAssignment)
|
|
183
|
+
return this.visitShorthandPropertyAssignment(node);
|
|
184
|
+
if (node instanceof Identifier)
|
|
185
|
+
return isIdentifierReference(node, this.parentNode) ? this.visitExpressionIdentifier(node) : node;
|
|
186
|
+
return this.visitEachChild(node);
|
|
187
|
+
}
|
|
188
|
+
// Source files
|
|
189
|
+
visitSourceFile(node) {
|
|
190
|
+
if (node.isDeclarationFile || !(isEffectiveExternalModule(node, this.options) || containsDynamicImport(node)))
|
|
191
|
+
return node;
|
|
192
|
+
this.currentSourceFile = node;
|
|
193
|
+
this.info = collectExternalModuleInfo(node, this.context, this.resolver);
|
|
194
|
+
const updated = this.transformCommonJSModule(node);
|
|
195
|
+
this.currentSourceFile = undefined;
|
|
196
|
+
this.info = undefined;
|
|
197
|
+
return updated;
|
|
198
|
+
}
|
|
199
|
+
shouldEmitUnderscoreUnderscoreESModule(file) {
|
|
200
|
+
if (fileExtensionIsOneOf(file.fileName, supportedJSExtensions) &&
|
|
201
|
+
file.commonJSModuleIndicator !== undefined &&
|
|
202
|
+
(file.externalModuleIndicator === undefined || file.externalModuleIndicator.kind === 307 /* SyntaxKind.SourceFile */))
|
|
203
|
+
return false;
|
|
204
|
+
return this.moduleInfo().exportEquals === undefined && isExternalModule(file);
|
|
205
|
+
}
|
|
206
|
+
/** `Object.defineProperty(exports, "__esModule", { value: true });` */
|
|
207
|
+
createUnderscoreUnderscoreESModule() {
|
|
208
|
+
const factory = this.factory;
|
|
209
|
+
const statement = factory.createExpressionStatement(factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('Object'), factory.createIdentifier('defineProperty')), [
|
|
210
|
+
factory.createIdentifier('exports'),
|
|
211
|
+
factory.createStringLiteral('__esModule', 0 /* TokenFlags.None */),
|
|
212
|
+
factory.createObjectLiteral([factory.createPropertyAssignment(factory.createIdentifier('value'), factory.createTrue())], false),
|
|
213
|
+
]));
|
|
214
|
+
this.context.setEmitFlags(statement, 65536 /* EmitFlags.CustomPrologue */);
|
|
215
|
+
return statement;
|
|
216
|
+
}
|
|
217
|
+
transformCommonJSModule(node) {
|
|
218
|
+
const factory = this.factory;
|
|
219
|
+
const context = this.context;
|
|
220
|
+
const info = this.moduleInfo();
|
|
221
|
+
context.startVariableEnvironment();
|
|
222
|
+
const source = node.statements.nodes;
|
|
223
|
+
const prologueEnd = standardPrologueEnd(source);
|
|
224
|
+
const statements = source.slice(0, prologueEnd);
|
|
225
|
+
const customEnd = this.customPrologueEnd(source, prologueEnd);
|
|
226
|
+
appendAll(statements, this.topLevel.visitArray(source.slice(prologueEnd, customEnd)));
|
|
227
|
+
if (this.shouldEmitUnderscoreUnderscoreESModule(node))
|
|
228
|
+
statements.push(this.createUnderscoreUnderscoreESModule());
|
|
229
|
+
// exports.a = exports.b = void 0;
|
|
230
|
+
const names = info.exportedNames;
|
|
231
|
+
for (let start = 0; start < names.length; start += 50) {
|
|
232
|
+
let right = factory.createVoidZero();
|
|
233
|
+
const end = Math.min(start + 50, names.length);
|
|
234
|
+
for (let i = start; i < end; i++)
|
|
235
|
+
right = factory.createAssignment(this.createExportsReference(names[i]), right);
|
|
236
|
+
const statement = factory.createExpressionStatement(right);
|
|
237
|
+
context.addEmitFlags(statement, 65536 /* EmitFlags.CustomPrologue */);
|
|
238
|
+
statements.push(statement);
|
|
239
|
+
}
|
|
240
|
+
// exports.f = f; ahead of the helpers import, as TypeScript orders them.
|
|
241
|
+
const functionsStart = statements.length;
|
|
242
|
+
for (let i = 0; i < info.exportedFunctions.length; i++)
|
|
243
|
+
this.appendExportsOfClassOrFunctionDeclaration(statements, info.exportedFunctions[i]);
|
|
244
|
+
for (let i = functionsStart; i < statements.length; i++)
|
|
245
|
+
context.addEmitFlags(statements[i], 65536 /* EmitFlags.CustomPrologue */);
|
|
246
|
+
appendAll(statements, this.topLevel.visitArray(source.slice(customEnd)));
|
|
247
|
+
this.appendExportEqualsIfNeeded(statements);
|
|
248
|
+
const merged = context.mergeEnvironment(statements, context.endVariableEnvironment());
|
|
249
|
+
let result = factory.updateSourceFile(node, new NodeList(node.statements.pos, node.statements.end, merged), node.endOfFileToken);
|
|
250
|
+
const helpers = context.readEmitHelpers();
|
|
251
|
+
for (let i = 0; i < helpers.length; i++)
|
|
252
|
+
context.addEmitHelper(result, helpers[i]);
|
|
253
|
+
const helpersImport = createExternalHelpersImportDeclarationIfNeeded(context, result, this.options, this.formats.getEmitModuleFormat(node.fileName));
|
|
254
|
+
if (helpersImport !== undefined) {
|
|
255
|
+
const current = result.statements.nodes;
|
|
256
|
+
const standardEnd = standardPrologueEnd(current);
|
|
257
|
+
const end = this.customPrologueEnd(current, standardEnd);
|
|
258
|
+
const withImport = current.slice(0, end);
|
|
259
|
+
const visited = this.topLevel.visitNode(helpersImport);
|
|
260
|
+
if (visited !== undefined)
|
|
261
|
+
withImport.push(visited);
|
|
262
|
+
appendAll(withImport, current.slice(end));
|
|
263
|
+
result = factory.updateSourceFile(result, new NodeList(result.statements.pos, result.statements.end, withImport), node.endOfFileToken);
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
customPrologueEnd(statements, start) {
|
|
268
|
+
let i = start;
|
|
269
|
+
while (i < statements.length &&
|
|
270
|
+
!isPrologueDirective(statements[i]) &&
|
|
271
|
+
(this.context.getEmitFlags(statements[i]) & 65536 /* EmitFlags.CustomPrologue */) !== 0)
|
|
272
|
+
i++;
|
|
273
|
+
return i;
|
|
274
|
+
}
|
|
275
|
+
/** `exports.x` or `exports["x"]` for an export name. */
|
|
276
|
+
createExportsReference(name) {
|
|
277
|
+
const factory = this.factory;
|
|
278
|
+
if (name instanceof StringLiteral)
|
|
279
|
+
return factory.createElementAccessExpression(factory.createIdentifier('exports'), factory.createStringLiteralFromNode(name));
|
|
280
|
+
const clone = this.cloneName(name);
|
|
281
|
+
this.context.setEmitFlags(clone, 12 /* EmitFlags.NoSourceMap */ | 384 /* EmitFlags.NoComments */);
|
|
282
|
+
return factory.createPropertyAccessExpression(factory.createIdentifier('exports'), clone);
|
|
283
|
+
}
|
|
284
|
+
cloneName(name) {
|
|
285
|
+
return name instanceof Identifier ? this.factory.cloneIdentifier(name) : name;
|
|
286
|
+
}
|
|
287
|
+
/** `module.exports = x;` for `export = x`. */
|
|
288
|
+
appendExportEqualsIfNeeded(statements) {
|
|
289
|
+
const exportEquals = this.moduleInfo().exportEquals;
|
|
290
|
+
if (exportEquals === undefined)
|
|
291
|
+
return false;
|
|
292
|
+
const grandparent = this.pushNode(exportEquals);
|
|
293
|
+
const expression = this.visitNode(exportEquals.expression);
|
|
294
|
+
this.popNode(grandparent);
|
|
295
|
+
if (expression === undefined)
|
|
296
|
+
return false;
|
|
297
|
+
const factory = this.factory;
|
|
298
|
+
const statement = factory.createExpressionStatement(factory.createAssignment(factory.createPropertyAccessExpression(factory.createIdentifier('module'), factory.createIdentifier('exports')), expression));
|
|
299
|
+
this.context.assignCommentAndSourceMapRanges(statement, exportEquals);
|
|
300
|
+
this.context.addEmitFlags(statement, 384 /* EmitFlags.NoComments */);
|
|
301
|
+
statements.push(statement);
|
|
302
|
+
return true;
|
|
303
|
+
}
|
|
304
|
+
// Exports of declarations
|
|
305
|
+
appendExportsOfImportDeclaration(statements, declaration) {
|
|
306
|
+
if (this.moduleInfo().exportEquals !== undefined)
|
|
307
|
+
return false;
|
|
308
|
+
const clause = declaration.importClause;
|
|
309
|
+
if (clause === undefined)
|
|
310
|
+
return false;
|
|
311
|
+
const seen = new Set();
|
|
312
|
+
if (clause.name !== undefined)
|
|
313
|
+
this.appendExportsOfDeclaration(statements, clause, seen, false);
|
|
314
|
+
const bindings = clause.namedBindings;
|
|
315
|
+
if (bindings !== undefined && bindings.kind === 275 /* SyntaxKind.NamespaceImport */)
|
|
316
|
+
this.appendExportsOfDeclaration(statements, bindings, seen, false);
|
|
317
|
+
else if (bindings !== undefined && bindings.kind === 276 /* SyntaxKind.NamedImports */) {
|
|
318
|
+
const elements = bindingElementsOf(bindings);
|
|
319
|
+
for (let i = 0; i < elements.length; i++)
|
|
320
|
+
this.appendExportsOfDeclaration(statements, elements[i], seen, true);
|
|
321
|
+
}
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
appendExportsOfVariableDeclarationList(statements, list, isForInOrOfInitializer) {
|
|
325
|
+
if (this.moduleInfo().exportEquals !== undefined)
|
|
326
|
+
return false;
|
|
327
|
+
const declarations = list.declarations.nodes;
|
|
328
|
+
for (let i = 0; i < declarations.length; i++)
|
|
329
|
+
this.appendExportsOfBindingElement(statements, declarations[i], isForInOrOfInitializer);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
appendExportsOfBindingElement(statements, declaration, isForInOrOfInitializer) {
|
|
333
|
+
if (this.moduleInfo().exportEquals !== undefined)
|
|
334
|
+
return false;
|
|
335
|
+
const name = bindingNameOf(declaration);
|
|
336
|
+
if (name === undefined)
|
|
337
|
+
return false;
|
|
338
|
+
if (name instanceof BindingPattern) {
|
|
339
|
+
const elements = name.elements.nodes;
|
|
340
|
+
for (let i = 0; i < elements.length; i++)
|
|
341
|
+
if (elements[i].kind !== 233 /* SyntaxKind.OmittedExpression */)
|
|
342
|
+
this.appendExportsOfBindingElement(statements, elements[i], isForInOrOfInitializer);
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
if (!this.context.hasAutoGenerateInfo(name) &&
|
|
346
|
+
(!(declaration instanceof VariableDeclaration) || declaration.initializer !== undefined || isForInOrOfInitializer))
|
|
347
|
+
this.appendExportsOfDeclaration(statements, declaration, undefined, false);
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
appendExportsOfClassOrFunctionDeclaration(statements, declaration) {
|
|
351
|
+
if (this.moduleInfo().exportEquals !== undefined)
|
|
352
|
+
return false;
|
|
353
|
+
const seen = new Set();
|
|
354
|
+
if (hasSyntacticModifier(declaration, 32 /* ModifierFlags.Export */)) {
|
|
355
|
+
const exportName = hasSyntacticModifier(declaration, 2048 /* ModifierFlags.Default */)
|
|
356
|
+
? this.factory.createIdentifier('default')
|
|
357
|
+
: this.factory.getDeclarationName(declaration, 0 /* NameOptions.None */);
|
|
358
|
+
this.appendExportStatement(statements, seen, exportName, this.factory.getLocalName(declaration, 0 /* NameOptions.None */), declaration, false, false);
|
|
359
|
+
}
|
|
360
|
+
if (declarationNameOf(declaration) !== undefined)
|
|
361
|
+
this.appendExportsOfDeclaration(statements, declaration, seen, false);
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
364
|
+
appendExportsOfDeclaration(statements, declaration, seenNames, liveBinding) {
|
|
365
|
+
const info = this.moduleInfo();
|
|
366
|
+
if (info.exportEquals !== undefined)
|
|
367
|
+
return false;
|
|
368
|
+
const seen = seenNames !== undefined ? seenNames : new Set();
|
|
369
|
+
if (info.exportSpecifiers.size === 0 || !(declarationNameOf(declaration) instanceof Identifier))
|
|
370
|
+
return false;
|
|
371
|
+
const name = this.factory.getDeclarationName(declaration, 0 /* NameOptions.None */);
|
|
372
|
+
const specifiers = info.exportSpecifiers.get(name.text);
|
|
373
|
+
if (specifiers === undefined || specifiers.length === 0)
|
|
374
|
+
return false;
|
|
375
|
+
const value = this.visitExpressionIdentifier(name);
|
|
376
|
+
for (let i = 0; i < specifiers.length; i++)
|
|
377
|
+
this.appendExportStatement(statements, seen, specifiers[i].name, value, specifiers[i].name, false, liveBinding);
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
appendExportStatement(statements, seen, exportName, value, location, allowComments, liveBinding) {
|
|
381
|
+
if (!(exportName instanceof StringLiteral)) {
|
|
382
|
+
const text = moduleExportNameText(exportName);
|
|
383
|
+
if (seen.has(text))
|
|
384
|
+
return false;
|
|
385
|
+
seen.add(text);
|
|
386
|
+
}
|
|
387
|
+
statements.push(this.createExportStatement(exportName, value, location, allowComments, liveBinding));
|
|
388
|
+
return true;
|
|
389
|
+
}
|
|
390
|
+
createExportStatement(name, value, location, allowComments, liveBinding) {
|
|
391
|
+
const statement = this.factory.createExpressionStatement(this.createExportExpression(name, value, undefined, liveBinding));
|
|
392
|
+
if (location !== undefined)
|
|
393
|
+
this.context.setCommentRange(statement, location.pos, location.end);
|
|
394
|
+
this.context.addEmitFlags(statement, 524288 /* EmitFlags.StartOnNewLine */);
|
|
395
|
+
if (!allowComments)
|
|
396
|
+
this.context.addEmitFlags(statement, 384 /* EmitFlags.NoComments */);
|
|
397
|
+
return statement;
|
|
398
|
+
}
|
|
399
|
+
/** `exports.x = value`, or a getter on `exports` for a live binding. */
|
|
400
|
+
createExportExpression(name, value, location, liveBinding) {
|
|
401
|
+
const factory = this.factory;
|
|
402
|
+
let expression;
|
|
403
|
+
if (liveBinding) {
|
|
404
|
+
// Object.defineProperty(exports, "x", { enumerable: true, get: function () { return value; } })
|
|
405
|
+
const getter = factory.createFunctionExpression([], factory.createBlock([factory.createReturnStatement(value)], false));
|
|
406
|
+
expression = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('Object'), factory.createIdentifier('defineProperty')), [
|
|
407
|
+
factory.createIdentifier('exports'),
|
|
408
|
+
factory.createStringLiteralFromNode(name),
|
|
409
|
+
factory.createObjectLiteral([
|
|
410
|
+
factory.createPropertyAssignment(factory.createIdentifier('enumerable'), factory.createTrue()),
|
|
411
|
+
factory.createPropertyAssignment(factory.createIdentifier('get'), getter),
|
|
412
|
+
], false),
|
|
413
|
+
]);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
const target = name instanceof StringLiteral
|
|
417
|
+
? factory.createElementAccessExpression(factory.createIdentifier('exports'), factory.createStringLiteralFromNode(name))
|
|
418
|
+
: factory.createPropertyAccessExpression(factory.createIdentifier('exports'), this.cloneName(name));
|
|
419
|
+
expression = factory.createAssignment(target, value);
|
|
420
|
+
}
|
|
421
|
+
if (location !== undefined)
|
|
422
|
+
this.context.setCommentRange(expression, location.pos, location.end);
|
|
423
|
+
return expression;
|
|
424
|
+
}
|
|
425
|
+
/** `require("mod")` */
|
|
426
|
+
createRequireCall(node) {
|
|
427
|
+
const factory = this.factory;
|
|
428
|
+
return factory.createCallExpression(factory.createIdentifier('require'), createRequireCallArguments(this.context, node, this.options));
|
|
429
|
+
}
|
|
430
|
+
getHelperExpressionForImport(node, inner) {
|
|
431
|
+
if (getImportNeedsImportStarHelper(node))
|
|
432
|
+
return this.visitNode(this.factory.createImportStarHelper(inner));
|
|
433
|
+
if (getImportNeedsImportDefaultHelper(node))
|
|
434
|
+
return this.visitNode(this.factory.createImportDefaultHelper(inner));
|
|
435
|
+
return inner;
|
|
436
|
+
}
|
|
437
|
+
// Top-level statements
|
|
438
|
+
visitTopLevelImportDeclaration(node) {
|
|
439
|
+
const factory = this.factory;
|
|
440
|
+
const context = this.context;
|
|
441
|
+
if (node.importClause === undefined) {
|
|
442
|
+
// import "mod";
|
|
443
|
+
const statement = factory.createExpressionStatement(this.createRequireCall(node));
|
|
444
|
+
context.setOriginal(statement, node);
|
|
445
|
+
context.assignCommentAndSourceMapRanges(statement, node);
|
|
446
|
+
return statement;
|
|
447
|
+
}
|
|
448
|
+
const variables = [];
|
|
449
|
+
const namespaceDeclaration = getNamespaceDeclarationNode(node);
|
|
450
|
+
if (namespaceDeclaration !== undefined && !isDefaultImport(node)) {
|
|
451
|
+
// import * as n from "mod";
|
|
452
|
+
variables.push(factory.createVariableDeclaration(this.cloneName(namespaceNameOf(namespaceDeclaration)), undefined, undefined, this.getHelperExpressionForImport(node, this.createRequireCall(node))));
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
// import d, { x } from "mod";
|
|
456
|
+
variables.push(factory.createVariableDeclaration(factory.createGeneratedNameForNode(node, 0, '', ''), undefined, undefined, this.getHelperExpressionForImport(node, this.createRequireCall(node))));
|
|
457
|
+
if (namespaceDeclaration !== undefined)
|
|
458
|
+
variables.push(factory.createVariableDeclaration(this.cloneName(namespaceNameOf(namespaceDeclaration)), undefined, undefined, factory.createGeneratedNameForNode(node, 0, '', '')));
|
|
459
|
+
}
|
|
460
|
+
const statement = factory.createVariableStatement(undefined, factory.createVariableDeclarationList(factory.createNodeList(variables), 2 /* NodeFlags.Const */));
|
|
461
|
+
context.setOriginal(statement, node);
|
|
462
|
+
context.assignCommentAndSourceMapRanges(statement, node);
|
|
463
|
+
const statements = [statement];
|
|
464
|
+
this.appendExportsOfImportDeclaration(statements, node);
|
|
465
|
+
return singleOrMany(statements, factory);
|
|
466
|
+
}
|
|
467
|
+
visitTopLevelImportEqualsDeclaration(node) {
|
|
468
|
+
const factory = this.factory;
|
|
469
|
+
const context = this.context;
|
|
470
|
+
if (!(node.moduleReference instanceof ExternalModuleReference))
|
|
471
|
+
return this.visitEachChild(node);
|
|
472
|
+
let statement;
|
|
473
|
+
if (hasSyntacticModifier(node, 32 /* ModifierFlags.Export */)) {
|
|
474
|
+
// export import m = require("mod");
|
|
475
|
+
statement = factory.createExpressionStatement(this.createExportExpression(node.name, this.createRequireCall(node), node, false));
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
// import m = require("mod");
|
|
479
|
+
statement = factory.createVariableStatement(undefined, factory.createVariableDeclarationList(factory.createNodeList([
|
|
480
|
+
factory.createVariableDeclaration(factory.cloneIdentifier(node.name), undefined, undefined, this.createRequireCall(node)),
|
|
481
|
+
]), 2 /* NodeFlags.Const */));
|
|
482
|
+
}
|
|
483
|
+
context.setOriginal(statement, node);
|
|
484
|
+
context.assignCommentAndSourceMapRanges(statement, node);
|
|
485
|
+
const statements = [statement];
|
|
486
|
+
this.appendExportsOfDeclaration(statements, node, undefined, false);
|
|
487
|
+
return singleOrMany(statements, factory);
|
|
488
|
+
}
|
|
489
|
+
visitTopLevelExportDeclaration(node) {
|
|
490
|
+
const factory = this.factory;
|
|
491
|
+
const context = this.context;
|
|
492
|
+
// Local `export { x }` is handled with the declarations it exports.
|
|
493
|
+
if (node.moduleSpecifier === undefined)
|
|
494
|
+
return undefined;
|
|
495
|
+
const generatedName = factory.createGeneratedNameForNode(node, 0, '', '');
|
|
496
|
+
const clause = node.exportClause;
|
|
497
|
+
if (clause instanceof NamedExports) {
|
|
498
|
+
// export { x, y } from "mod";
|
|
499
|
+
const statement = factory.createVariableStatement(undefined, factory.createVariableDeclarationList(factory.createNodeList([
|
|
500
|
+
factory.createVariableDeclaration(generatedName, undefined, undefined, this.createRequireCall(node)),
|
|
501
|
+
]), 0 /* NodeFlags.None */));
|
|
502
|
+
context.setOriginal(statement, node);
|
|
503
|
+
context.assignCommentAndSourceMapRanges(statement, node);
|
|
504
|
+
const statements = [statement];
|
|
505
|
+
const specifiers = clause.elements.nodes;
|
|
506
|
+
for (let i = 0; i < specifiers.length; i++) {
|
|
507
|
+
const specifier = specifiers[i];
|
|
508
|
+
if (!(specifier instanceof ExportSpecifier))
|
|
509
|
+
continue;
|
|
510
|
+
const imported = specifier.propertyName !== undefined ? specifier.propertyName : specifier.name;
|
|
511
|
+
const target = moduleExportNameText(imported) === 'default'
|
|
512
|
+
? factory.createImportDefaultHelper(generatedName)
|
|
513
|
+
: generatedName;
|
|
514
|
+
const exportName = specifier.name instanceof StringLiteral
|
|
515
|
+
? factory.createStringLiteralFromNode(specifier.name)
|
|
516
|
+
: factory.getExportName(specifier, 0 /* NameOptions.None */);
|
|
517
|
+
const value = imported instanceof StringLiteral
|
|
518
|
+
? factory.createElementAccessExpression(target, imported)
|
|
519
|
+
: factory.createPropertyAccessExpression(target, imported);
|
|
520
|
+
const exportStatement = factory.createExpressionStatement(this.createExportExpression(exportName, value, undefined, true));
|
|
521
|
+
context.setOriginal(exportStatement, specifier);
|
|
522
|
+
context.assignCommentAndSourceMapRanges(exportStatement, specifier);
|
|
523
|
+
statements.push(exportStatement);
|
|
524
|
+
}
|
|
525
|
+
return singleOrMany(statements, factory);
|
|
526
|
+
}
|
|
527
|
+
if (clause instanceof NamespaceExport) {
|
|
528
|
+
// export * as ns from "mod";
|
|
529
|
+
const name = clause.name;
|
|
530
|
+
const exportName = name instanceof StringLiteral ? factory.createStringLiteralFromNode(name) : this.cloneName(name);
|
|
531
|
+
const statement = factory.createExpressionStatement(this.createExportExpression(exportName, this.visitNode(factory.createImportStarHelper(this.createRequireCall(node))), undefined, false));
|
|
532
|
+
context.setOriginal(statement, node);
|
|
533
|
+
context.assignCommentAndSourceMapRanges(statement, node);
|
|
534
|
+
return statement;
|
|
535
|
+
}
|
|
536
|
+
// export * from "mod";
|
|
537
|
+
const statement = factory.createExpressionStatement(this.visitNode(factory.createExportStarHelper(this.createRequireCall(node), factory.createIdentifier('exports'))));
|
|
538
|
+
context.setOriginal(statement, node);
|
|
539
|
+
context.assignCommentAndSourceMapRanges(statement, node);
|
|
540
|
+
return statement;
|
|
541
|
+
}
|
|
542
|
+
visitTopLevelExportAssignment(node) {
|
|
543
|
+
if (node.isExportEquals)
|
|
544
|
+
return undefined;
|
|
545
|
+
return this.createExportStatement(this.factory.createIdentifier('default'), this.visitNode(node.expression), node, true, false);
|
|
546
|
+
}
|
|
547
|
+
visitTopLevelFunctionDeclaration(node) {
|
|
548
|
+
if (!hasSyntacticModifier(node, 32 /* ModifierFlags.Export */))
|
|
549
|
+
return this.visitEachChild(node);
|
|
550
|
+
return this.factory.updateFunctionDeclaration(node, this.extractModifiers(node.modifiers, ~exportDefault), node.asteriskToken, this.factory.getDeclarationName(node, 0 /* NameOptions.None */), undefined, this.visitNodes(node.parameters), undefined, undefined, this.visitNode(node.body));
|
|
551
|
+
}
|
|
552
|
+
visitTopLevelClassDeclaration(node) {
|
|
553
|
+
const statements = [];
|
|
554
|
+
if (hasSyntacticModifier(node, 32 /* ModifierFlags.Export */)) {
|
|
555
|
+
const updated = this.factory.updateClassDeclaration(node, this.visitModifiers(this.extractModifiers(node.modifiers, ~exportDefault)), this.factory.getDeclarationName(node, 0 /* NameOptions.None */), undefined, this.visitNodes(node.heritageClauses), this.visitNodes(node.members));
|
|
556
|
+
if (updated !== undefined)
|
|
557
|
+
statements.push(updated);
|
|
558
|
+
}
|
|
559
|
+
else
|
|
560
|
+
statements.push(this.visitEachChild(node));
|
|
561
|
+
this.appendExportsOfClassOrFunctionDeclaration(statements, node);
|
|
562
|
+
return singleOrMany(statements, this.factory);
|
|
563
|
+
}
|
|
564
|
+
visitTopLevelVariableStatement(node) {
|
|
565
|
+
if (!hasSyntacticModifier(node, 32 /* ModifierFlags.Export */)) {
|
|
566
|
+
// Nested `var`s may still be exported with `export { x }`.
|
|
567
|
+
const statements = [this.visitEachChild(node)];
|
|
568
|
+
this.appendExportsOfVariableDeclarationList(statements, node.declarationList, false);
|
|
569
|
+
return singleOrMany(statements, this.factory);
|
|
570
|
+
}
|
|
571
|
+
// export var a = b; becomes exports.a = b;
|
|
572
|
+
const factory = this.factory;
|
|
573
|
+
const context = this.context;
|
|
574
|
+
const splitter = new ExportedVariableSplitter(this, node);
|
|
575
|
+
const declarations = node.declarationList.declarations.nodes;
|
|
576
|
+
for (let i = 0; i < declarations.length; i++) {
|
|
577
|
+
const variable = declarations[i];
|
|
578
|
+
if (!(variable instanceof VariableDeclaration))
|
|
579
|
+
continue;
|
|
580
|
+
const name = variable.name;
|
|
581
|
+
const initializer = variable.initializer;
|
|
582
|
+
if (name instanceof Identifier && (context.getEmitFlags(name) & 4096 /* EmitFlags.LocalName */) !== 0) {
|
|
583
|
+
// A class or function converted to a variable: references stay local, an `export { x }` follows.
|
|
584
|
+
splitter.ensureModifiers();
|
|
585
|
+
splitter.pushVariable(initializer === undefined
|
|
586
|
+
? variable
|
|
587
|
+
: factory.updateVariableDeclaration(variable, name, undefined, undefined, this.createExportExpression(name, this.visitNode(initializer), undefined, false)));
|
|
588
|
+
}
|
|
589
|
+
else if (initializer !== undefined &&
|
|
590
|
+
!(name instanceof BindingPattern) &&
|
|
591
|
+
(initializer instanceof ArrowFunction ||
|
|
592
|
+
initializer instanceof FunctionExpression ||
|
|
593
|
+
initializer instanceof ClassExpression)) {
|
|
594
|
+
// Variables keep functions and classes named.
|
|
595
|
+
splitter.pushVariable(factory.createVariableDeclaration(name, variable.exclamationToken, variable.type, this.visitNode(initializer)));
|
|
596
|
+
const access = factory.createPropertyAccessExpression(factory.createIdentifier('exports'), name);
|
|
597
|
+
context.assignCommentAndSourceMapRanges(access, name);
|
|
598
|
+
splitter.pushExpression(factory.createAssignment(access, this.cloneName(name)));
|
|
599
|
+
}
|
|
600
|
+
else if (name instanceof Identifier) {
|
|
601
|
+
const expression = this.transformInitializedVariable(variable);
|
|
602
|
+
if (expression !== undefined)
|
|
603
|
+
splitter.pushExpression(this.visitNode(expression));
|
|
604
|
+
}
|
|
605
|
+
else if (name instanceof BindingPattern) {
|
|
606
|
+
const expression = this.transformInitializedVariable(variable);
|
|
607
|
+
if (expression !== undefined)
|
|
608
|
+
splitter.pushExpression(expression);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
const expression = convertVariableDeclarationToAssignment(this, variable);
|
|
612
|
+
if (expression !== undefined)
|
|
613
|
+
splitter.pushExpression(this.visitNode(expression));
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
splitter.commitVariables();
|
|
617
|
+
splitter.commitExpressions();
|
|
618
|
+
const statements = splitter.statements;
|
|
619
|
+
this.appendExportsOfVariableDeclarationList(statements, node.declarationList, false);
|
|
620
|
+
return singleOrMany(statements, factory);
|
|
621
|
+
}
|
|
622
|
+
transformInitializedVariable(node) {
|
|
623
|
+
const initializer = node.initializer;
|
|
624
|
+
if (initializer === undefined)
|
|
625
|
+
return undefined;
|
|
626
|
+
const name = node.name;
|
|
627
|
+
if (name instanceof BindingPattern) {
|
|
628
|
+
// Kept as native destructuring unless a target can't be rewritten to `exports.x`.
|
|
629
|
+
const assignment = convertVariableDeclarationToAssignment(this, node);
|
|
630
|
+
const grandparent = this.pushNode(assignment);
|
|
631
|
+
const result = assignment instanceof BinaryExpression ? this.visitDestructuringAssignment(assignment, true) : assignment;
|
|
632
|
+
this.popNode(grandparent);
|
|
633
|
+
return result;
|
|
634
|
+
}
|
|
635
|
+
const access = this.factory.createPropertyAccessExpression(this.factory.createIdentifier('exports'), name);
|
|
636
|
+
this.context.assignCommentAndSourceMapRanges(access, name);
|
|
637
|
+
return this.factory.createAssignment(access, initializer);
|
|
638
|
+
}
|
|
639
|
+
visitTopLevelNestedForStatement(node) {
|
|
640
|
+
const factory = this.factory;
|
|
641
|
+
const initializer = node.initializer;
|
|
642
|
+
if (initializer instanceof VariableDeclarationList && (initializer.flags & 7 /* NodeFlags.BlockScoped */) === 0) {
|
|
643
|
+
const exports = [];
|
|
644
|
+
this.appendExportsOfVariableDeclarationList(exports, initializer, false);
|
|
645
|
+
if (exports.length > 0) {
|
|
646
|
+
// var x = 0; exports.x = x; for (; ;) { }
|
|
647
|
+
const list = this.discarded.visitNode(initializer);
|
|
648
|
+
const statements = [
|
|
649
|
+
factory.createVariableStatement(undefined, list instanceof VariableDeclarationList
|
|
650
|
+
? list
|
|
651
|
+
: initializer),
|
|
652
|
+
];
|
|
653
|
+
appendAll(statements, exports);
|
|
654
|
+
const updated = factory.updateForStatement(node, undefined, this.visitNode(node.condition), this.discarded.visitNode(node.incrementor), this.topLevelNested.visitIterationBody(node.statement));
|
|
655
|
+
if (updated !== undefined)
|
|
656
|
+
statements.push(updated);
|
|
657
|
+
return singleOrMany(statements, factory);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
return factory.updateForStatement(node, this.discarded.visitNode(initializer), this.visitNode(node.condition), this.discarded.visitNode(node.incrementor), this.topLevelNested.visitIterationBody(node.statement));
|
|
661
|
+
}
|
|
662
|
+
visitTopLevelNestedForInOrOfStatement(node) {
|
|
663
|
+
const factory = this.factory;
|
|
664
|
+
const initializer = node.initializer;
|
|
665
|
+
if (initializer instanceof VariableDeclarationList && (initializer.flags & 7 /* NodeFlags.BlockScoped */) === 0) {
|
|
666
|
+
const exports = [];
|
|
667
|
+
this.appendExportsOfVariableDeclarationList(exports, initializer, true);
|
|
668
|
+
if (exports.length > 0) {
|
|
669
|
+
// for (var x in y) { exports.x = x; ... }
|
|
670
|
+
const visitedInitializer = this.discarded.visitNode(initializer);
|
|
671
|
+
const expression = this.visitNode(node.expression);
|
|
672
|
+
const body = this.topLevelNested.visitIterationBody(node.statement);
|
|
673
|
+
let updatedBody;
|
|
674
|
+
if (body instanceof Block) {
|
|
675
|
+
const block = factory.updateBlock(body, new NodeList(body.statements.pos, body.statements.end, exports.concat(body.statements.nodes)), body.multiLine);
|
|
676
|
+
updatedBody = block !== undefined ? block : body;
|
|
677
|
+
}
|
|
678
|
+
else {
|
|
679
|
+
exports.push(body);
|
|
680
|
+
updatedBody = factory.createBlock(exports, true);
|
|
681
|
+
}
|
|
682
|
+
return factory.updateForInOrOfStatement(node, node.awaitModifier, visitedInitializer, expression, updatedBody);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return factory.updateForInOrOfStatement(node, node.awaitModifier, this.discarded.visitNode(initializer), this.visitNode(node.expression), this.topLevelNested.visitIterationBody(node.statement));
|
|
686
|
+
}
|
|
687
|
+
// Expressions
|
|
688
|
+
visitBinaryExpression(node, discarded) {
|
|
689
|
+
if (isDestructuringAssignment(node))
|
|
690
|
+
return this.visitDestructuringAssignment(node, discarded);
|
|
691
|
+
if (isAssignmentExpression(node, false))
|
|
692
|
+
return this.visitAssignmentExpression(node);
|
|
693
|
+
if (node.operatorToken.kind === 27 /* SyntaxKind.CommaToken */)
|
|
694
|
+
return this.factory.updateBinaryExpression(node, undefined, this.discarded.visitNode(node.left), undefined, node.operatorToken, (discarded ? this.discarded.visitNode(node.right) : this.visitNode(node.right)));
|
|
695
|
+
return this.visitEachChild(node);
|
|
696
|
+
}
|
|
697
|
+
/** Assigning an exported name also assigns each of its exports. */
|
|
698
|
+
visitAssignmentExpression(node) {
|
|
699
|
+
const left = node.left;
|
|
700
|
+
if (left instanceof Identifier && this.isSubstitutableName(left)) {
|
|
701
|
+
const exportedNames = this.getExports(left);
|
|
702
|
+
if (exportedNames !== undefined && exportedNames.length > 0) {
|
|
703
|
+
let expression = this.visitEachChild(node);
|
|
704
|
+
for (let i = 0; i < exportedNames.length; i++)
|
|
705
|
+
expression = this.createExportExpression(exportedNames[i], expression, node, false);
|
|
706
|
+
return expression;
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
return this.visitEachChild(node);
|
|
710
|
+
}
|
|
711
|
+
/** Not generated (except file-level reserved names) and not a local name. */
|
|
712
|
+
isSubstitutableName(name) {
|
|
713
|
+
const context = this.context;
|
|
714
|
+
return ((!context.hasAutoGenerateInfo(name) || this.isFileLevelReservedGeneratedIdentifier(name)) &&
|
|
715
|
+
(context.getEmitFlags(name) & 4096 /* EmitFlags.LocalName */) === 0);
|
|
716
|
+
}
|
|
717
|
+
visitDestructuringAssignment(node, discarded) {
|
|
718
|
+
if (this.destructuringNeedsFlattening(node.left))
|
|
719
|
+
return flattenDestructuringAssignment(this, node, !discarded, this.exportAssignments);
|
|
720
|
+
return this.visitEachChild(node);
|
|
721
|
+
}
|
|
722
|
+
/** Whether a destructuring target assigns an exported name that native destructuring can't update. */
|
|
723
|
+
destructuringNeedsFlattening(node) {
|
|
724
|
+
if (node instanceof ObjectLiteralExpression) {
|
|
725
|
+
const properties = node.properties.nodes;
|
|
726
|
+
for (let i = 0; i < properties.length; i++) {
|
|
727
|
+
const element = properties[i];
|
|
728
|
+
if (element instanceof PropertyAssignment) {
|
|
729
|
+
if (this.destructuringNeedsFlattening(element.initializer))
|
|
730
|
+
return true;
|
|
731
|
+
}
|
|
732
|
+
else if (element instanceof ShorthandPropertyAssignment) {
|
|
733
|
+
if (this.destructuringNeedsFlattening(element.name))
|
|
734
|
+
return true;
|
|
735
|
+
}
|
|
736
|
+
else if (element instanceof SpreadAssignment) {
|
|
737
|
+
if (this.destructuringNeedsFlattening(element.expression))
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
else if (element.kind === 175 /* SyntaxKind.MethodDeclaration */ ||
|
|
741
|
+
element.kind === 178 /* SyntaxKind.GetAccessor */ ||
|
|
742
|
+
element.kind === 179 /* SyntaxKind.SetAccessor */)
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
return false;
|
|
746
|
+
}
|
|
747
|
+
if (node instanceof ArrayLiteralExpression) {
|
|
748
|
+
const elements = node.elements.nodes;
|
|
749
|
+
for (let i = 0; i < elements.length; i++) {
|
|
750
|
+
const element = elements[i];
|
|
751
|
+
const target = element instanceof SpreadElement ? element.expression : element;
|
|
752
|
+
if (this.destructuringNeedsFlattening(target))
|
|
753
|
+
return true;
|
|
754
|
+
}
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
if (node instanceof Identifier) {
|
|
758
|
+
const exportedNames = this.getExports(node);
|
|
759
|
+
const count = exportedNames === undefined ? 0 : exportedNames.length;
|
|
760
|
+
if ((this.context.getEmitFlags(node) & 2048 /* EmitFlags.ExportName */) !== 0)
|
|
761
|
+
return count > 1;
|
|
762
|
+
if (count === 0)
|
|
763
|
+
return false;
|
|
764
|
+
// A single direct export of the same name becomes `exports.x` natively.
|
|
765
|
+
if (count === 1 &&
|
|
766
|
+
this.isDirectExport(node) &&
|
|
767
|
+
moduleExportNameText(exportedNames[0]) === node.text)
|
|
768
|
+
return false;
|
|
769
|
+
return true;
|
|
770
|
+
}
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
/** The assignment of a flattened destructuring target, assigning its exports too. */
|
|
774
|
+
createAllExportExpressions(name, value, pos, end) {
|
|
775
|
+
const factory = this.factory;
|
|
776
|
+
const exportedNames = this.getExports(name);
|
|
777
|
+
if (exportedNames !== undefined && exportedNames.length > 0) {
|
|
778
|
+
let expression = this.isDirectExport(name)
|
|
779
|
+
? this.createDirectExportAssignment(name, value)
|
|
780
|
+
: factory.createAssignment(name, value);
|
|
781
|
+
for (let i = 0; i < exportedNames.length; i++) {
|
|
782
|
+
expression = this.createExportExpression(exportedNames[i], expression, undefined, false);
|
|
783
|
+
this.context.setCommentRange(expression, pos, end);
|
|
784
|
+
}
|
|
785
|
+
return expression;
|
|
786
|
+
}
|
|
787
|
+
if (this.isDirectExport(name))
|
|
788
|
+
return this.createDirectExportAssignment(name, value);
|
|
789
|
+
return factory.createAssignment(name, value);
|
|
790
|
+
}
|
|
791
|
+
/** `exports.x = value` for a directly exported `x`. */
|
|
792
|
+
createDirectExportAssignment(name, value) {
|
|
793
|
+
const factory = this.factory;
|
|
794
|
+
const context = this.context;
|
|
795
|
+
const exportName = factory.cloneIdentifier(name);
|
|
796
|
+
context.addEmitFlags(exportName, 384 /* EmitFlags.NoComments */ | 12 /* EmitFlags.NoSourceMap */);
|
|
797
|
+
const access = factory.createPropertyAccessExpression(factory.createIdentifier('exports'), exportName);
|
|
798
|
+
context.addEmitFlags(access, 384 /* EmitFlags.NoComments */);
|
|
799
|
+
const assignment = factory.createAssignment(access, value);
|
|
800
|
+
context.assignCommentAndSourceMapRanges(assignment, name);
|
|
801
|
+
return assignment;
|
|
802
|
+
}
|
|
803
|
+
/** Whether `name` refers to a declaration exported by the module itself, like `export let x`. */
|
|
804
|
+
isDirectExport(name) {
|
|
805
|
+
const location = this.context.mostOriginal(name);
|
|
806
|
+
if (!(location instanceof Identifier) || (location.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
807
|
+
return false;
|
|
808
|
+
return this.resolver.getReferencedExportContainer(location, false) instanceof SourceFile;
|
|
809
|
+
}
|
|
810
|
+
visitPrefixUnaryExpression(node) {
|
|
811
|
+
const operand = node.operand;
|
|
812
|
+
if ((node.operator === 45 /* SyntaxKind.PlusPlusToken */ || node.operator === 46 /* SyntaxKind.MinusMinusToken */) &&
|
|
813
|
+
operand instanceof Identifier &&
|
|
814
|
+
(this.context.getEmitFlags(operand) & 4096 /* EmitFlags.LocalName */) === 0) {
|
|
815
|
+
const exportedNames = this.getExports(operand);
|
|
816
|
+
if (exportedNames !== undefined && exportedNames.length > 0) {
|
|
817
|
+
// exports.x = ++x;
|
|
818
|
+
let expression = this.factory.updatePrefixUnaryExpression(node, node.operator, this.visitNode(operand));
|
|
819
|
+
for (let i = 0; i < exportedNames.length; i++) {
|
|
820
|
+
expression = this.createExportExpression(exportedNames[i], expression, undefined, false);
|
|
821
|
+
this.context.assignCommentAndSourceMapRanges(expression, node);
|
|
822
|
+
}
|
|
823
|
+
return expression;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
return this.visitEachChild(node);
|
|
827
|
+
}
|
|
828
|
+
visitPostfixUnaryExpression(node, discarded) {
|
|
829
|
+
const operand = node.operand;
|
|
830
|
+
if ((node.operator === 45 /* SyntaxKind.PlusPlusToken */ || node.operator === 46 /* SyntaxKind.MinusMinusToken */) &&
|
|
831
|
+
operand instanceof Identifier &&
|
|
832
|
+
(this.context.getEmitFlags(operand) & 4096 /* EmitFlags.LocalName */) === 0) {
|
|
833
|
+
const exportedNames = this.getExports(operand);
|
|
834
|
+
if (exportedNames !== undefined && exportedNames.length > 0) {
|
|
835
|
+
// exports.x = (x++, x); or, when the value is used: (exports.x = (_a = x++, x), _a)
|
|
836
|
+
const factory = this.factory;
|
|
837
|
+
const context = this.context;
|
|
838
|
+
let temp = undefined;
|
|
839
|
+
let expression = factory.updatePostfixUnaryExpression(node, this.visitNode(operand), node.operator);
|
|
840
|
+
if (!discarded) {
|
|
841
|
+
temp = factory.createTempVariable(0);
|
|
842
|
+
context.addVariableDeclaration(temp);
|
|
843
|
+
expression = factory.createAssignment(temp, expression);
|
|
844
|
+
context.assignCommentAndSourceMapRanges(expression, node);
|
|
845
|
+
}
|
|
846
|
+
expression = factory.createCommaExpression(expression, factory.cloneIdentifier(operand));
|
|
847
|
+
context.assignCommentAndSourceMapRanges(expression, node);
|
|
848
|
+
for (let i = 0; i < exportedNames.length; i++) {
|
|
849
|
+
expression = this.createExportExpression(exportedNames[i], expression, undefined, false);
|
|
850
|
+
context.assignCommentAndSourceMapRanges(expression, node);
|
|
851
|
+
}
|
|
852
|
+
if (temp !== undefined) {
|
|
853
|
+
expression = factory.createCommaExpression(expression, temp);
|
|
854
|
+
context.assignCommentAndSourceMapRanges(expression, node);
|
|
855
|
+
}
|
|
856
|
+
return expression;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
return this.visitEachChild(node);
|
|
860
|
+
}
|
|
861
|
+
/** `(0, mod_1.f)()` for a call of an import; `import()` becomes a `require` call. */
|
|
862
|
+
visitCallExpression(node) {
|
|
863
|
+
const rewrite = this.options.rewriteRelativeImportExtensions === true &&
|
|
864
|
+
((isImportCall(node) && node.arguments.nodes.length > 0) || (isInJSFile(node) && isRequireCall(node, false)));
|
|
865
|
+
if (isImportCall(node) && this.shouldTransformImportCall())
|
|
866
|
+
return this.visitImportCallExpression(node, rewrite);
|
|
867
|
+
if (rewrite)
|
|
868
|
+
return this.rewriteImportOrRequireCall(node);
|
|
869
|
+
const callee = node.expression;
|
|
870
|
+
if (callee instanceof Identifier) {
|
|
871
|
+
const expression = this.visitExpressionIdentifier(callee);
|
|
872
|
+
const updated = this.factory.updateCallExpression(node, expression, node.questionDotToken, undefined, this.visitNodes(node.arguments), node.flags);
|
|
873
|
+
if (!(expression instanceof Identifier) && (this.context.getEmitFlags(callee) & 1024 /* EmitFlags.HelperName */) === 0)
|
|
874
|
+
this.context.addEmitFlags(updated, 1048576 /* EmitFlags.IndirectCall */);
|
|
875
|
+
return updated;
|
|
876
|
+
}
|
|
877
|
+
return this.visitEachChild(node);
|
|
878
|
+
}
|
|
879
|
+
shouldTransformImportCall() {
|
|
880
|
+
const kind = this.moduleKind;
|
|
881
|
+
if ((kind >= ModuleKind.Node16 && kind <= ModuleKind.NodeNext) || kind === ModuleKind.Preserve)
|
|
882
|
+
return false;
|
|
883
|
+
return this.formats.getEmitModuleFormat(this.currentSourceFile.fileName) < ModuleKind.ES2015;
|
|
884
|
+
}
|
|
885
|
+
visitImportCallExpression(node, rewrite) {
|
|
886
|
+
if (this.moduleKind === ModuleKind.None && this.languageVersion >= ScriptTarget.ES2020)
|
|
887
|
+
return this.visitEachChild(node);
|
|
888
|
+
const factory = this.factory;
|
|
889
|
+
const specifier = getExternalModuleName(node);
|
|
890
|
+
const moduleName = specifier instanceof StringLiteral ? factory.createStringLiteral(specifier.text, 0 /* TokenFlags.None */) : undefined;
|
|
891
|
+
const args = node.arguments.nodes;
|
|
892
|
+
const first = args.length > 0 ? this.visitNode(args[0]) : undefined;
|
|
893
|
+
// The module name only where it differs from the argument, which keeps the argument's quotes.
|
|
894
|
+
let argument;
|
|
895
|
+
if (moduleName !== undefined && (!(first instanceof StringLiteral) || first.text !== moduleName.text))
|
|
896
|
+
argument = moduleName;
|
|
897
|
+
else if (first !== undefined && rewrite)
|
|
898
|
+
argument =
|
|
899
|
+
first instanceof StringLiteral
|
|
900
|
+
? rewriteModuleSpecifier(this.context, first, this.options)
|
|
901
|
+
: factory.createRewriteRelativeImportExtensionsHelper(first, this.options.jsx === JsxEmit.Preserve);
|
|
902
|
+
else
|
|
903
|
+
argument = first;
|
|
904
|
+
return this.createImportCallExpressionCommonJS(argument);
|
|
905
|
+
}
|
|
906
|
+
/** `Promise.resolve().then(() => __importStar(require(x)))` */
|
|
907
|
+
createImportCallExpressionCommonJS(argument) {
|
|
908
|
+
const factory = this.factory;
|
|
909
|
+
// A non-literal argument is converted to a string synchronously, as `import()` does.
|
|
910
|
+
const needSyncEval = argument !== undefined && !isSimpleInlineableExpression(argument);
|
|
911
|
+
const resolveArguments = [];
|
|
912
|
+
if (needSyncEval)
|
|
913
|
+
resolveArguments.push(factory.created(new TemplateExpression(factory.created(new TemplateHead('', '', 0 /* TokenFlags.None */)), factory.createNodeList([
|
|
914
|
+
factory.created(new TemplateSpan(argument, factory.created(new TemplateTail('', '', 0 /* TokenFlags.None */)))),
|
|
915
|
+
]))));
|
|
916
|
+
const promiseResolve = factory.createCallExpression(factory.createPropertyAccessExpression(factory.createIdentifier('Promise'), factory.createIdentifier('resolve')), resolveArguments);
|
|
917
|
+
const requireArguments = needSyncEval
|
|
918
|
+
? [factory.createIdentifier('s')]
|
|
919
|
+
: argument !== undefined
|
|
920
|
+
? [argument]
|
|
921
|
+
: [];
|
|
922
|
+
const requireCall = factory.createImportStarHelper(factory.createCallExpression(factory.createIdentifier('require'), requireArguments));
|
|
923
|
+
const parameters = needSyncEval ? [factory.createParameter(factory.createIdentifier('s'))] : [];
|
|
924
|
+
return factory.createCallExpression(factory.createPropertyAccessExpression(promiseResolve, factory.createIdentifier('then')), [factory.createArrowFunction(parameters, requireCall)]);
|
|
925
|
+
}
|
|
926
|
+
rewriteImportOrRequireCall(node) {
|
|
927
|
+
const factory = this.factory;
|
|
928
|
+
const expression = this.visitNode(node.expression);
|
|
929
|
+
let args = node.arguments;
|
|
930
|
+
const nodes = args.nodes;
|
|
931
|
+
if (nodes.length > 0) {
|
|
932
|
+
const first = nodes[0];
|
|
933
|
+
const rewritten = first instanceof StringLiteral || first.kind === 14 /* SyntaxKind.NoSubstitutionTemplateLiteral */
|
|
934
|
+
? rewriteModuleSpecifier(this.context, first, this.options)
|
|
935
|
+
: factory.createRewriteRelativeImportExtensionsHelper(first, this.options.jsx === JsxEmit.Preserve);
|
|
936
|
+
const rest = nodes.slice(1);
|
|
937
|
+
const visitedRest = this.visitArray(rest);
|
|
938
|
+
if (rewritten !== first || visitedRest !== rest)
|
|
939
|
+
args = new NodeList(args.pos, args.end, [rewritten].concat(visitedRest));
|
|
940
|
+
}
|
|
941
|
+
return factory.updateCallExpression(node, expression, node.questionDotToken, undefined, args, node.flags);
|
|
942
|
+
}
|
|
943
|
+
visitTaggedTemplateExpression(node) {
|
|
944
|
+
const tag = node.tag;
|
|
945
|
+
if (!(tag instanceof Identifier))
|
|
946
|
+
return this.visitEachChild(node);
|
|
947
|
+
const expression = this.visitExpressionIdentifier(tag);
|
|
948
|
+
const updated = this.factory.updateTaggedTemplateExpression(node, expression, undefined, undefined, this.visitNode(node.template), node.flags);
|
|
949
|
+
if (!(expression instanceof Identifier) && (this.context.getEmitFlags(tag) & 1024 /* EmitFlags.HelperName */) === 0)
|
|
950
|
+
this.context.addEmitFlags(updated, 1048576 /* EmitFlags.IndirectCall */);
|
|
951
|
+
return updated;
|
|
952
|
+
}
|
|
953
|
+
visitShorthandPropertyAssignment(node) {
|
|
954
|
+
const factory = this.factory;
|
|
955
|
+
const name = node.name;
|
|
956
|
+
const reference = name instanceof Identifier ? this.visitExpressionIdentifier(name) : name;
|
|
957
|
+
if (reference !== name) {
|
|
958
|
+
// `{ x }` becomes `{ x: exports.x }`; with an initializer, it's part of a destructuring assignment.
|
|
959
|
+
let expression = reference;
|
|
960
|
+
if (node.objectAssignmentInitializer !== undefined)
|
|
961
|
+
expression = factory.createAssignment(expression, this.visitNode(node.objectAssignmentInitializer));
|
|
962
|
+
const assignment = factory.createPropertyAssignment(name, expression);
|
|
963
|
+
assignment.pos = node.pos;
|
|
964
|
+
assignment.end = node.end;
|
|
965
|
+
this.context.assignCommentAndSourceMapRanges(assignment, node);
|
|
966
|
+
return assignment;
|
|
967
|
+
}
|
|
968
|
+
return factory.updateShorthandPropertyAssignment(node, undefined, reference, undefined, undefined, node.equalsToken, this.visitNode(node.objectAssignmentInitializer));
|
|
969
|
+
}
|
|
970
|
+
/** `exports.x` for an exported name, `mod_1.x` or `mod_1.default` for an import. */
|
|
971
|
+
visitExpressionIdentifier(node) {
|
|
972
|
+
const context = this.context;
|
|
973
|
+
const factory = this.factory;
|
|
974
|
+
const info = context.getAutoGenerateInfo(node);
|
|
975
|
+
if ((info !== undefined && (info.flags & 64 /* GeneratedIdentifierFlags.AllowNameSubstitution */) === 0) ||
|
|
976
|
+
(context.getEmitFlags(node) & (1024 /* EmitFlags.HelperName */ | 4096 /* EmitFlags.LocalName */)) !== 0 ||
|
|
977
|
+
isDeclarationNameOfEnumOrNamespace(context.mostOriginal(node)))
|
|
978
|
+
return node;
|
|
979
|
+
const location = context.mostOriginal(node);
|
|
980
|
+
if (!(location instanceof Identifier))
|
|
981
|
+
return node;
|
|
982
|
+
// Generated names, such as the JSX transform's `_jsx`, may still refer to an import.
|
|
983
|
+
const synthesized = (location.flags & 16 /* NodeFlags.Synthesized */) !== 0;
|
|
984
|
+
const container = synthesized
|
|
985
|
+
? undefined
|
|
986
|
+
: this.resolver.getReferencedExportContainer(location, (context.getEmitFlags(node) & 2048 /* EmitFlags.ExportName */) !== 0);
|
|
987
|
+
if (container instanceof SourceFile) {
|
|
988
|
+
const reference = factory.createPropertyAccessExpression(factory.createIdentifier('exports'), factory.cloneIdentifier(node));
|
|
989
|
+
context.assignCommentAndSourceMapRanges(reference, node);
|
|
990
|
+
reference.pos = node.pos;
|
|
991
|
+
reference.end = node.end;
|
|
992
|
+
return reference;
|
|
993
|
+
}
|
|
994
|
+
const declaration = this.resolver.getReferencedImportDeclaration(location);
|
|
995
|
+
if (declaration instanceof ImportClause && declaration.parent !== undefined) {
|
|
996
|
+
const reference = factory.createPropertyAccessExpression(factory.createGeneratedNameForNode(declaration.parent, 0, '', ''), factory.createIdentifier('default'));
|
|
997
|
+
context.assignCommentAndSourceMapRanges(reference, node);
|
|
998
|
+
reference.pos = node.pos;
|
|
999
|
+
reference.end = node.end;
|
|
1000
|
+
return reference;
|
|
1001
|
+
}
|
|
1002
|
+
if (declaration instanceof ImportSpecifier) {
|
|
1003
|
+
const imported = declaration.propertyName !== undefined ? declaration.propertyName : declaration.name;
|
|
1004
|
+
const importDeclaration = findImportDeclaration(declaration);
|
|
1005
|
+
const target = factory.createGeneratedNameForNode(importDeclaration !== undefined ? importDeclaration : declaration, 0, '', '');
|
|
1006
|
+
let reference;
|
|
1007
|
+
if (imported instanceof StringLiteral)
|
|
1008
|
+
reference = factory.createElementAccessExpression(target, factory.createStringLiteralFromNode(imported));
|
|
1009
|
+
else {
|
|
1010
|
+
const name = imported instanceof Identifier ? factory.cloneIdentifier(imported) : imported;
|
|
1011
|
+
context.addEmitFlags(name, 12 /* EmitFlags.NoSourceMap */ | 384 /* EmitFlags.NoComments */);
|
|
1012
|
+
reference = factory.createPropertyAccessExpression(target, name);
|
|
1013
|
+
}
|
|
1014
|
+
context.assignCommentAndSourceMapRanges(reference, node);
|
|
1015
|
+
reference.pos = node.pos;
|
|
1016
|
+
reference.end = node.end;
|
|
1017
|
+
return reference;
|
|
1018
|
+
}
|
|
1019
|
+
return node;
|
|
1020
|
+
}
|
|
1021
|
+
/** The export names of what `name` refers to. */
|
|
1022
|
+
getExports(name) {
|
|
1023
|
+
const context = this.context;
|
|
1024
|
+
const info = this.moduleInfo();
|
|
1025
|
+
if (!context.hasAutoGenerateInfo(name)) {
|
|
1026
|
+
const location = context.mostOriginal(name);
|
|
1027
|
+
if (!(location instanceof Identifier) || (location.flags & 16 /* NodeFlags.Synthesized */) !== 0)
|
|
1028
|
+
return undefined;
|
|
1029
|
+
const importDeclaration = this.resolver.getReferencedImportDeclaration(location);
|
|
1030
|
+
if (importDeclaration !== undefined)
|
|
1031
|
+
return info.getExportedBindings(importDeclaration);
|
|
1032
|
+
// An exported namespace or enum may merge with ambient declarations, so all value declarations count.
|
|
1033
|
+
const declarations = this.resolver.getReferencedValueDeclarations(location);
|
|
1034
|
+
if (declarations === undefined)
|
|
1035
|
+
return undefined;
|
|
1036
|
+
const bindings = [];
|
|
1037
|
+
for (let i = 0; i < declarations.length; i++) {
|
|
1038
|
+
const exported = info.getExportedBindings(declarations[i]);
|
|
1039
|
+
if (exported === undefined)
|
|
1040
|
+
continue;
|
|
1041
|
+
for (let j = 0; j < exported.length; j++)
|
|
1042
|
+
if (bindings.indexOf(exported[j]) < 0)
|
|
1043
|
+
bindings.push(exported[j]);
|
|
1044
|
+
}
|
|
1045
|
+
return bindings;
|
|
1046
|
+
}
|
|
1047
|
+
if (this.isFileLevelReservedGeneratedIdentifier(name)) {
|
|
1048
|
+
const specifiers = info.exportSpecifiers.get(name.text);
|
|
1049
|
+
if (specifiers === undefined)
|
|
1050
|
+
return undefined;
|
|
1051
|
+
const names = [];
|
|
1052
|
+
for (let i = 0; i < specifiers.length; i++)
|
|
1053
|
+
names.push(specifiers[i].name);
|
|
1054
|
+
return names;
|
|
1055
|
+
}
|
|
1056
|
+
return undefined;
|
|
1057
|
+
}
|
|
1058
|
+
isFileLevelReservedGeneratedIdentifier(name) {
|
|
1059
|
+
const info = this.context.getAutoGenerateInfo(name);
|
|
1060
|
+
const flags = 32 /* GeneratedIdentifierFlags.FileLevel */ |
|
|
1061
|
+
16 /* GeneratedIdentifierFlags.Optimistic */ |
|
|
1062
|
+
8 /* GeneratedIdentifierFlags.ReservedInNestedScopes */;
|
|
1063
|
+
return info !== undefined && (info.flags & flags) === flags;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
/** Builds the statements of an exported variable statement, grouping declarations and assignments. */
|
|
1067
|
+
class ExportedVariableSplitter {
|
|
1068
|
+
owner;
|
|
1069
|
+
node;
|
|
1070
|
+
statements;
|
|
1071
|
+
variables;
|
|
1072
|
+
expressions;
|
|
1073
|
+
modifiers;
|
|
1074
|
+
hasModifiers;
|
|
1075
|
+
constructor(owner, node) {
|
|
1076
|
+
this.owner = owner;
|
|
1077
|
+
this.node = node;
|
|
1078
|
+
this.statements = [];
|
|
1079
|
+
this.variables = [];
|
|
1080
|
+
this.expressions = [];
|
|
1081
|
+
this.modifiers = undefined;
|
|
1082
|
+
this.hasModifiers = false;
|
|
1083
|
+
}
|
|
1084
|
+
ensureModifiers() {
|
|
1085
|
+
if (!this.hasModifiers) {
|
|
1086
|
+
this.modifiers = this.owner.extractModifiers(this.node.modifiers, ~exportDefault);
|
|
1087
|
+
this.hasModifiers = true;
|
|
1088
|
+
}
|
|
1089
|
+
return true;
|
|
1090
|
+
}
|
|
1091
|
+
pushVariable(variable) {
|
|
1092
|
+
this.commitExpressions();
|
|
1093
|
+
this.variables.push(variable);
|
|
1094
|
+
return true;
|
|
1095
|
+
}
|
|
1096
|
+
pushExpression(expression) {
|
|
1097
|
+
this.commitVariables();
|
|
1098
|
+
this.expressions.push(expression);
|
|
1099
|
+
return true;
|
|
1100
|
+
}
|
|
1101
|
+
commitVariables() {
|
|
1102
|
+
if (this.variables.length === 0)
|
|
1103
|
+
return false;
|
|
1104
|
+
const factory = this.owner.factory;
|
|
1105
|
+
const list = this.node.declarationList;
|
|
1106
|
+
const statement = factory.updateVariableStatement(this.node, this.modifiers, factory.updateVariableDeclarationList(list, factory.createNodeList(this.variables), list.flags));
|
|
1107
|
+
if (this.statements.length > 0)
|
|
1108
|
+
this.owner.context.addEmitFlags(statement, 384 /* EmitFlags.NoComments */);
|
|
1109
|
+
this.statements.push(statement);
|
|
1110
|
+
this.variables = [];
|
|
1111
|
+
return true;
|
|
1112
|
+
}
|
|
1113
|
+
commitExpressions() {
|
|
1114
|
+
if (this.expressions.length === 0)
|
|
1115
|
+
return false;
|
|
1116
|
+
const factory = this.owner.factory;
|
|
1117
|
+
const statement = factory.createExpressionStatement(factory.inlineExpressions(this.expressions));
|
|
1118
|
+
this.owner.context.assignCommentAndSourceMapRanges(statement, this.node);
|
|
1119
|
+
if (this.statements.length > 0)
|
|
1120
|
+
this.owner.context.addEmitFlags(statement, 384 /* EmitFlags.NoComments */);
|
|
1121
|
+
this.statements.push(statement);
|
|
1122
|
+
this.expressions = [];
|
|
1123
|
+
return true;
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
function appendAll(target, source) {
|
|
1127
|
+
for (let i = 0; i < source.length; i++)
|
|
1128
|
+
target.push(source[i]);
|
|
1129
|
+
return target;
|
|
1130
|
+
}
|
|
1131
|
+
function standardPrologueEnd(statements) {
|
|
1132
|
+
let i = 0;
|
|
1133
|
+
while (i < statements.length && isPrologueDirective(statements[i]))
|
|
1134
|
+
i++;
|
|
1135
|
+
return i;
|
|
1136
|
+
}
|
|
1137
|
+
function bindingElementsOf(node) {
|
|
1138
|
+
const elements = getElements(node);
|
|
1139
|
+
return elements === undefined ? [] : elements.nodes;
|
|
1140
|
+
}
|
|
1141
|
+
function bindingNameOf(node) {
|
|
1142
|
+
return getName(node);
|
|
1143
|
+
}
|
|
1144
|
+
function declarationNameOf(node) {
|
|
1145
|
+
return getName(node);
|
|
1146
|
+
}
|
|
1147
|
+
function namespaceNameOf(node) {
|
|
1148
|
+
return getName(node);
|
|
1149
|
+
}
|
|
1150
|
+
function findImportDeclaration(node) {
|
|
1151
|
+
for (let current = node; current !== undefined; current = current.parent)
|
|
1152
|
+
if (current instanceof ImportDeclaration)
|
|
1153
|
+
return current;
|
|
1154
|
+
return undefined;
|
|
1155
|
+
}
|
|
1156
|
+
function isDeclarationNameOfEnumOrNamespace(original) {
|
|
1157
|
+
const parent = original.parent;
|
|
1158
|
+
if (parent === undefined)
|
|
1159
|
+
return false;
|
|
1160
|
+
if (parent.kind !== 267 /* SyntaxKind.EnumDeclaration */ && parent.kind !== 268 /* SyntaxKind.ModuleDeclaration */)
|
|
1161
|
+
return false;
|
|
1162
|
+
return getName(parent) === original;
|
|
1163
|
+
}
|
|
1164
|
+
/** A literal or keyword: copied into several places without side effects. */
|
|
1165
|
+
function isSimpleInlineableExpression(node) {
|
|
1166
|
+
return !(node instanceof Identifier) && isSimpleCopiableExpression(node);
|
|
1167
|
+
}
|
|
1168
|
+
/** Whether a file has `import()` calls. */
|
|
1169
|
+
function containsDynamicImport(file) {
|
|
1170
|
+
const finder = new DynamicImportFinder();
|
|
1171
|
+
return file.forEachChild(finder);
|
|
1172
|
+
}
|
|
1173
|
+
class DynamicImportFinder extends NodeVisitor {
|
|
1174
|
+
visitNode(node) {
|
|
1175
|
+
// `import()`, not `import.defer()`.
|
|
1176
|
+
if (node instanceof CallExpression && node.expression.kind === 101 /* SyntaxKind.ImportKeyword */)
|
|
1177
|
+
return true;
|
|
1178
|
+
return node.forEachChild(this);
|
|
1179
|
+
}
|
|
1180
|
+
}
|