tsc-ts 0.0.9 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/tsc-ts.js +70 -1
- package/dist/api/compiler/ast-utilities.d.ts +19 -1
- package/dist/api/compiler/ast-utilities.js +180 -95
- package/dist/api/compiler/ast.d.ts +22 -15
- package/dist/api/compiler/ast.js +1026 -995
- package/dist/api/compiler/astnav.js +15 -15
- package/dist/api/compiler/binder-utilities.js +186 -186
- package/dist/api/compiler/binder.js +290 -263
- package/dist/api/compiler/character-codes.js +2 -2
- package/dist/api/compiler/checker-calls.js +178 -124
- package/dist/api/compiler/checker-classes.d.ts +14 -3
- package/dist/api/compiler/checker-classes.js +134 -90
- package/dist/api/compiler/checker-contextual.js +64 -61
- package/dist/api/compiler/checker-declaration-order.js +79 -79
- package/dist/api/compiler/checker-declarations.d.ts +1 -0
- package/dist/api/compiler/checker-declarations.js +160 -136
- package/dist/api/compiler/checker-declared-types.js +67 -65
- package/dist/api/compiler/checker-decorators.js +77 -77
- package/dist/api/compiler/checker-deprecation.d.ts +8 -3
- package/dist/api/compiler/checker-deprecation.js +76 -55
- package/dist/api/compiler/checker-destructuring.js +47 -45
- package/dist/api/compiler/checker-elaboration.js +24 -24
- package/dist/api/compiler/checker-emit-helpers.js +4 -4
- package/dist/api/compiler/checker-emit-resolver.d.ts +4 -2
- package/dist/api/compiler/checker-emit-resolver.js +25 -13
- package/dist/api/compiler/checker-evaluator.js +9 -9
- package/dist/api/compiler/checker-expressions.js +244 -211
- package/dist/api/compiler/checker-functions.js +113 -107
- package/dist/api/compiler/checker-generated-code.d.ts +0 -11
- package/dist/api/compiler/checker-generated-code.js +28 -52
- package/dist/api/compiler/checker-grammar.d.ts +1 -0
- package/dist/api/compiler/checker-grammar.js +472 -440
- package/dist/api/compiler/checker-heritage.js +91 -93
- package/dist/api/compiler/checker-inference.d.ts +77 -5
- package/dist/api/compiler/checker-inference.js +487 -107
- package/dist/api/compiler/checker-iteration.d.ts +0 -10
- package/dist/api/compiler/checker-iteration.js +35 -52
- package/dist/api/compiler/checker-javascript.js +14 -14
- package/dist/api/compiler/checker-jsdoc.d.ts +8 -10
- package/dist/api/compiler/checker-jsdoc.js +67 -58
- package/dist/api/compiler/checker-jsx.js +105 -88
- package/dist/api/compiler/checker-members.d.ts +9 -2
- package/dist/api/compiler/checker-members.js +212 -75
- package/dist/api/compiler/checker-modules.d.ts +15 -6
- package/dist/api/compiler/checker-modules.js +469 -309
- package/dist/api/compiler/checker-narrowing.js +273 -189
- package/dist/api/compiler/checker-object-literals.js +25 -22
- package/dist/api/compiler/checker-operators.js +126 -118
- package/dist/api/compiler/checker-overloads.js +27 -27
- package/dist/api/compiler/checker-property-access.js +59 -55
- package/dist/api/compiler/checker-services.d.ts +1 -0
- package/dist/api/compiler/checker-services.js +222 -210
- package/dist/api/compiler/checker-signatures.js +65 -49
- package/dist/api/compiler/checker-source-file.d.ts +5 -0
- package/dist/api/compiler/checker-source-file.js +154 -130
- package/dist/api/compiler/checker-statements.js +33 -32
- package/dist/api/compiler/checker-super.js +50 -50
- package/dist/api/compiler/checker-symbol-types.js +109 -93
- package/dist/api/compiler/checker-symbols.d.ts +13 -1
- package/dist/api/compiler/checker-symbols.js +264 -149
- package/dist/api/compiler/checker-type-factory.d.ts +5 -0
- package/dist/api/compiler/checker-type-factory.js +145 -36
- package/dist/api/compiler/checker-type-nodes.d.ts +1 -0
- package/dist/api/compiler/checker-type-nodes.js +179 -141
- package/dist/api/compiler/checker-type-operators.d.ts +2 -0
- package/dist/api/compiler/checker-type-operators.js +110 -63
- package/dist/api/compiler/checker-types.d.ts +80 -3
- package/dist/api/compiler/checker-types.js +121 -2
- package/dist/api/compiler/checker-unused.js +114 -118
- package/dist/api/compiler/checker-utilities.js +11 -11
- package/dist/api/compiler/checker.d.ts +104 -31
- package/dist/api/compiler/checker.js +181 -33
- package/dist/api/compiler/command-line.d.ts +1 -3
- package/dist/api/compiler/command-line.js +47 -44
- package/dist/api/compiler/compile-program.d.ts +42 -3
- package/dist/api/compiler/compile-program.js +139 -27
- package/dist/api/compiler/diagnostic-messages.d.ts +1849 -1774
- package/dist/api/compiler/diagnostic-messages.js +128 -122
- package/dist/api/compiler/diagnostics.d.ts +22 -0
- package/dist/api/compiler/diagnostics.js +93 -11
- package/dist/api/compiler/emitter.d.ts +7 -1
- package/dist/api/compiler/emitter.js +53 -11
- package/dist/api/compiler/file-include.d.ts +2 -1
- package/dist/api/compiler/file-include.js +11 -7
- package/dist/api/compiler/file-loader.d.ts +21 -1
- package/dist/api/compiler/file-loader.js +201 -48
- package/dist/api/compiler/instantiation.d.ts +7 -0
- package/dist/api/compiler/instantiation.js +101 -49
- package/dist/api/compiler/jsdoc.js +23 -23
- package/dist/api/compiler/link-tables.d.ts +48 -18
- package/dist/api/compiler/link-tables.js +80 -37
- package/dist/api/compiler/locales/cs-CZ.d.ts +1 -1
- package/dist/api/compiler/locales/cs-CZ.js +1 -1
- package/dist/api/compiler/locales/de-DE.d.ts +1 -1
- package/dist/api/compiler/locales/de-DE.js +1 -1
- package/dist/api/compiler/locales/es-ES.d.ts +1 -1
- package/dist/api/compiler/locales/es-ES.js +1 -1
- package/dist/api/compiler/locales/fr-FR.d.ts +1 -1
- package/dist/api/compiler/locales/fr-FR.js +1 -1
- package/dist/api/compiler/locales/it-IT.d.ts +1 -1
- package/dist/api/compiler/locales/it-IT.js +1 -1
- package/dist/api/compiler/locales/ja-JP.d.ts +1 -1
- package/dist/api/compiler/locales/ja-JP.js +1 -1
- package/dist/api/compiler/locales/ko-KR.d.ts +1 -1
- package/dist/api/compiler/locales/ko-KR.js +1 -1
- package/dist/api/compiler/locales/pl-PL.d.ts +1 -1
- package/dist/api/compiler/locales/pl-PL.js +1 -1
- package/dist/api/compiler/locales/pt-BR.d.ts +1 -1
- package/dist/api/compiler/locales/pt-BR.js +1 -1
- package/dist/api/compiler/locales/ru-RU.d.ts +1 -1
- package/dist/api/compiler/locales/ru-RU.js +1 -1
- package/dist/api/compiler/locales/tr-TR.d.ts +1 -1
- package/dist/api/compiler/locales/tr-TR.js +1 -1
- package/dist/api/compiler/locales/zh-CN.d.ts +1 -1
- package/dist/api/compiler/locales/zh-CN.js +1 -1
- package/dist/api/compiler/locales/zh-TW.d.ts +1 -1
- package/dist/api/compiler/locales/zh-TW.js +1 -1
- package/dist/api/compiler/module-resolution-types.js +6 -6
- package/dist/api/compiler/module-resolution.d.ts +10 -1
- package/dist/api/compiler/module-resolution.js +115 -84
- package/dist/api/compiler/module-specifiers.d.ts +15 -0
- package/dist/api/compiler/module-specifiers.js +24 -18
- package/dist/api/compiler/name-resolver.js +74 -65
- package/dist/api/compiler/node-builder-names.d.ts +11 -3
- package/dist/api/compiler/node-builder-names.js +210 -90
- package/dist/api/compiler/node-builder-pseudo.js +29 -31
- package/dist/api/compiler/node-builder-reuse.js +23 -22
- package/dist/api/compiler/node-builder.d.ts +18 -1
- package/dist/api/compiler/node-builder.js +191 -102
- package/dist/api/compiler/option-declarations.d.ts +2 -6
- package/dist/api/compiler/option-declarations.js +315 -375
- package/dist/api/compiler/options.d.ts +15 -33
- package/dist/api/compiler/options.js +21 -54
- package/dist/api/compiler/output-paths.d.ts +4 -1
- package/dist/api/compiler/output-paths.js +6 -11
- package/dist/api/compiler/package-json.d.ts +3 -3
- package/dist/api/compiler/package-json.js +11 -10
- package/dist/api/compiler/parallel-parse.d.ts +3 -2
- package/dist/api/compiler/parallel-parse.js +17 -5
- package/dist/api/compiler/parser.d.ts +40 -19
- package/dist/api/compiler/parser.js +308 -216
- package/dist/api/compiler/path.d.ts +9 -0
- package/dist/api/compiler/path.js +20 -3
- package/dist/api/compiler/printer/emit-context.d.ts +5 -1
- package/dist/api/compiler/printer/emit-context.js +20 -1
- package/dist/api/compiler/printer/factory-base.d.ts +2 -2
- package/dist/api/compiler/printer/factory-base.js +7 -3
- package/dist/api/compiler/printer/factory.js +3 -1
- package/dist/api/compiler/printer/helpers.js +10 -1
- package/dist/api/compiler/printer/name-generator.d.ts +1 -1
- package/dist/api/compiler/printer/name-generator.js +35 -16
- package/dist/api/compiler/printer/printer.d.ts +49 -2
- package/dist/api/compiler/printer/printer.js +539 -293
- package/dist/api/compiler/printer/utilities.js +149 -147
- package/dist/api/compiler/program-checker.d.ts +12 -2
- package/dist/api/compiler/program-checker.js +88 -34
- package/dist/api/compiler/program-utilities.d.ts +3 -1
- package/dist/api/compiler/program-utilities.js +28 -15
- package/dist/api/compiler/program.d.ts +4 -6
- package/dist/api/compiler/program.js +74 -87
- package/dist/api/compiler/pseudo-bigint.d.ts +2 -0
- package/dist/api/compiler/pseudo-bigint.js +18 -0
- package/dist/api/compiler/regexp-checker.d.ts +1 -1
- package/dist/api/compiler/regexp-checker.js +93 -76
- package/dist/api/compiler/relations.d.ts +27 -4
- package/dist/api/compiler/relations.js +347 -180
- package/dist/api/compiler/reparser.js +60 -56
- package/dist/api/compiler/scanner.d.ts +19 -2
- package/dist/api/compiler/scanner.js +123 -108
- package/dist/api/compiler/shared-results.d.ts +463 -0
- package/dist/api/compiler/shared-results.js +2128 -0
- package/dist/api/compiler/sourcemap.js +2 -2
- package/dist/api/compiler/symbol-accessibility.js +87 -74
- package/dist/api/compiler/symbol.d.ts +23 -14
- package/dist/api/compiler/symbol.js +23 -11
- package/dist/api/compiler/syntax-kind.d.ts +198 -197
- package/dist/api/compiler/transformers/alias-references.js +247 -139
- package/dist/api/compiler/transformers/async-utilities.js +25 -25
- package/dist/api/compiler/transformers/async.d.ts +0 -1
- package/dist/api/compiler/transformers/async.js +64 -77
- package/dist/api/compiler/transformers/class-fields.d.ts +1 -0
- package/dist/api/compiler/transformers/class-fields.js +81 -78
- package/dist/api/compiler/transformers/commonjs-module.js +18 -15
- package/dist/api/compiler/transformers/const-enum-inliner.js +1 -1
- package/dist/api/compiler/transformers/declarations-diagnostics.js +247 -244
- package/dist/api/compiler/transformers/declarations-pseudo.js +100 -100
- package/dist/api/compiler/transformers/declarations-resolver.d.ts +0 -3
- package/dist/api/compiler/transformers/declarations-syntactic.d.ts +1 -2
- package/dist/api/compiler/transformers/declarations-syntactic.js +134 -156
- package/dist/api/compiler/transformers/declarations-tracker.js +18 -18
- package/dist/api/compiler/transformers/declarations.d.ts +4 -1
- package/dist/api/compiler/transformers/declarations.js +305 -238
- package/dist/api/compiler/transformers/decorator-metadata.d.ts +1 -1
- package/dist/api/compiler/transformers/decorator-metadata.js +53 -45
- package/dist/api/compiler/transformers/decorator-utilities.js +24 -24
- package/dist/api/compiler/transformers/destructuring.js +19 -18
- package/dist/api/compiler/transformers/emit-resolver.js +1 -1
- package/dist/api/compiler/transformers/es-decorators.js +55 -55
- package/dist/api/compiler/transformers/external-module-info.js +3 -3
- package/dist/api/compiler/transformers/for-await.js +25 -25
- package/dist/api/compiler/transformers/import-elision.js +14 -14
- package/dist/api/compiler/transformers/jsx.js +12 -12
- package/dist/api/compiler/transformers/legacy-decorators.js +17 -17
- package/dist/api/compiler/transformers/module.js +8 -8
- package/dist/api/compiler/transformers/named-evaluation.js +4 -4
- package/dist/api/compiler/transformers/object-rest-spread.js +20 -20
- package/dist/api/compiler/transformers/optional-chain.js +10 -10
- package/dist/api/compiler/transformers/reference-resolver.d.ts +12 -1
- package/dist/api/compiler/transformers/reference-resolver.js +131 -69
- package/dist/api/compiler/transformers/runtime-syntax.js +35 -31
- package/dist/api/compiler/transformers/subtree-facts.js +47 -47
- package/dist/api/compiler/transformers/syntax-facts.js +56 -58
- package/dist/api/compiler/transformers/type-eraser.js +73 -66
- package/dist/api/compiler/transformers/type-serialization.js +24 -24
- package/dist/api/compiler/transformers/using.js +12 -12
- package/dist/api/compiler/transformers/utilities.js +77 -77
- package/dist/api/compiler/transformers/visitor-base.js +172 -172
- package/dist/api/compiler/transformers/visitor-hooks.js +6 -2
- package/dist/api/compiler/tsconfig.d.ts +10 -2
- package/dist/api/compiler/tsconfig.js +136 -48
- package/dist/api/compiler/type-printer.js +40 -3
- package/dist/api/compiler/types.d.ts +2 -1
- package/dist/api/library/ast.generated.d.ts +42 -39
- package/dist/api/library/ast.generated.js +1 -1
- package/dist/api/library/compiler-options.generated.d.ts +111 -100
- package/dist/api/library/compiler-options.generated.js +1 -1
- package/dist/api/library/disk.js +12 -1
- package/dist/api/library/enums.generated.d.ts +206 -206
- package/dist/api/library/enums.generated.js +206 -206
- package/dist/api/library/nodes.js +26 -26
- package/package.json +9 -9
- package/src/compiler/ast-utilities.ts +99 -7
- package/src/compiler/ast.ts +58 -26
- package/src/compiler/binder.ts +39 -4
- package/src/compiler/character-codes.ts +2 -2
- package/src/compiler/checker-calls.ts +79 -9
- package/src/compiler/checker-classes.ts +78 -24
- package/src/compiler/checker-contextual.ts +6 -1
- package/src/compiler/checker-declarations.ts +31 -4
- package/src/compiler/checker-declared-types.ts +8 -5
- package/src/compiler/checker-decorators.ts +1 -1
- package/src/compiler/checker-deprecation.ts +29 -8
- package/src/compiler/checker-destructuring.ts +10 -3
- package/src/compiler/checker-emit-helpers.ts +1 -0
- package/src/compiler/checker-emit-resolver.ts +16 -6
- package/src/compiler/checker-expressions.ts +79 -46
- package/src/compiler/checker-functions.ts +21 -6
- package/src/compiler/checker-generated-code.ts +2 -22
- package/src/compiler/checker-grammar.ts +136 -62
- package/src/compiler/checker-heritage.ts +22 -21
- package/src/compiler/checker-inference.ts +514 -82
- package/src/compiler/checker-iteration.ts +18 -31
- package/src/compiler/checker-javascript.ts +1 -1
- package/src/compiler/checker-jsdoc.ts +50 -27
- package/src/compiler/checker-jsx.ts +26 -4
- package/src/compiler/checker-members.ts +200 -56
- package/src/compiler/checker-modules.ts +332 -65
- package/src/compiler/checker-narrowing.ts +98 -19
- package/src/compiler/checker-object-literals.ts +3 -0
- package/src/compiler/checker-operators.ts +11 -4
- package/src/compiler/checker-property-access.ts +7 -2
- package/src/compiler/checker-services.ts +39 -12
- package/src/compiler/checker-signatures.ts +15 -1
- package/src/compiler/checker-source-file.ts +39 -13
- package/src/compiler/checker-statements.ts +3 -2
- package/src/compiler/checker-symbol-types.ts +29 -6
- package/src/compiler/checker-symbols.ts +158 -15
- package/src/compiler/checker-type-factory.ts +124 -23
- package/src/compiler/checker-type-nodes.ts +46 -3
- package/src/compiler/checker-type-operators.ts +83 -26
- package/src/compiler/checker-types.ts +147 -4
- package/src/compiler/checker-unused.ts +9 -14
- package/src/compiler/checker.ts +203 -39
- package/src/compiler/command-line.ts +28 -28
- package/src/compiler/compile-program.ts +167 -27
- package/src/compiler/decoder.ts +13 -4
- package/src/compiler/diagnostic-messages.ts +1973 -1892
- package/src/compiler/diagnostics.ts +84 -3
- package/src/compiler/emitter.ts +57 -8
- package/src/compiler/encoder.ts +23 -8
- package/src/compiler/file-include.ts +9 -3
- package/src/compiler/file-loader.ts +197 -38
- package/src/compiler/help.ts +10 -14
- package/src/compiler/incremental.ts +165 -30
- package/src/compiler/init.ts +2 -7
- package/src/compiler/instantiation.ts +77 -22
- package/src/compiler/jsdoc.ts +3 -1
- package/src/compiler/link-tables.ts +82 -37
- package/src/compiler/locales/cs-CZ.ts +1 -1
- package/src/compiler/locales/de-DE.ts +1 -1
- package/src/compiler/locales/es-ES.ts +1 -1
- package/src/compiler/locales/fr-FR.ts +1 -1
- package/src/compiler/locales/it-IT.ts +1 -1
- package/src/compiler/locales/ja-JP.ts +1 -1
- package/src/compiler/locales/ko-KR.ts +1 -1
- package/src/compiler/locales/pl-PL.ts +1 -1
- package/src/compiler/locales/pt-BR.ts +1 -1
- package/src/compiler/locales/ru-RU.ts +1 -1
- package/src/compiler/locales/tr-TR.ts +1 -1
- package/src/compiler/locales/zh-CN.ts +1 -1
- package/src/compiler/locales/zh-TW.ts +1 -1
- package/src/compiler/module-resolution.ts +44 -8
- package/src/compiler/module-specifiers.ts +62 -20
- package/src/compiler/name-resolver.ts +9 -1
- package/src/compiler/node-builder-names.ts +236 -54
- package/src/compiler/node-builder-pseudo.ts +4 -7
- package/src/compiler/node-builder-reuse.ts +5 -4
- package/src/compiler/node-builder.ts +130 -31
- package/src/compiler/option-declarations.ts +33 -103
- package/src/compiler/options.ts +23 -62
- package/src/compiler/output-paths.ts +5 -18
- package/src/compiler/package-entrypoints.ts +345 -0
- package/src/compiler/package-json.ts +4 -4
- package/src/compiler/parallel-check.ts +326 -52
- package/src/compiler/parallel-emit.ts +320 -0
- package/src/compiler/parallel-parse.ts +16 -5
- package/src/compiler/parse-thread.ts +3 -0
- package/src/compiler/parser.ts +156 -39
- package/src/compiler/path.ts +22 -2
- package/src/compiler/printer/emit-context.ts +21 -0
- package/src/compiler/printer/factory-base.ts +10 -3
- package/src/compiler/printer/factory.ts +4 -1
- package/src/compiler/printer/helpers.ts +10 -1
- package/src/compiler/printer/name-generator.ts +24 -2
- package/src/compiler/printer/printer.ts +266 -30
- package/src/compiler/printer/utilities.ts +8 -2
- package/src/compiler/program-checker.ts +57 -5
- package/src/compiler/program-utilities.ts +23 -10
- package/src/compiler/program.ts +18 -26
- package/src/compiler/pseudo-bigint.ts +17 -0
- package/src/compiler/regexp-checker.ts +63 -30
- package/src/compiler/relations.ts +240 -77
- package/src/compiler/reparser.ts +7 -2
- package/src/compiler/scanner.ts +109 -79
- package/src/compiler/shared-results.ts +2414 -0
- package/src/compiler/show-config.ts +18 -1
- package/src/compiler/sourcemap.ts +2 -2
- package/src/compiler/symbol-accessibility.ts +26 -3
- package/src/compiler/symbol.ts +46 -24
- package/src/compiler/syntax-kind.ts +188 -187
- package/src/compiler/thread-entry.ts +64 -4
- package/src/compiler/transformers/alias-references.ts +123 -4
- package/src/compiler/transformers/async.ts +2 -17
- package/src/compiler/transformers/class-fields.ts +13 -12
- package/src/compiler/transformers/commonjs-module.ts +11 -7
- package/src/compiler/transformers/declarations-diagnostics.ts +5 -3
- package/src/compiler/transformers/declarations-pseudo.ts +2 -4
- package/src/compiler/transformers/declarations-resolver.ts +0 -3
- package/src/compiler/transformers/declarations-syntactic.ts +1 -21
- package/src/compiler/transformers/declarations.ts +134 -48
- package/src/compiler/transformers/decorator-metadata.ts +9 -1
- package/src/compiler/transformers/destructuring.ts +4 -3
- package/src/compiler/transformers/external-module-info.ts +1 -1
- package/src/compiler/transformers/jsx.ts +2 -1
- package/src/compiler/transformers/reference-resolver.ts +83 -19
- package/src/compiler/transformers/runtime-syntax.ts +6 -1
- package/src/compiler/transformers/syntax-facts.ts +2 -7
- package/src/compiler/transformers/type-eraser.ts +10 -1
- package/src/compiler/transformers/type-serialization.ts +3 -2
- package/src/compiler/transformers/visitor-base.ts +2 -1
- package/src/compiler/transformers/visitor-hooks.ts +9 -4
- package/src/compiler/tsc-build.ts +66 -9
- package/src/compiler/tsc-cli.ts +7 -0
- package/src/compiler/tsc-compile.ts +284 -4
- package/src/compiler/tsc-watch.ts +74 -45
- package/src/compiler/tsconfig.ts +176 -19
- package/src/compiler/type-printer.ts +36 -2
- package/src/compiler/types.ts +2 -1
- package/src/library/ast.generated.ts +57 -41
- package/src/library/compiler-options.generated.ts +117 -103
- package/src/library/disk.ts +10 -1
- package/src/library/enums.generated.ts +196 -196
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// their annotations or the resolver, and elides imports the output doesn't use.
|
|
4
4
|
import { getJSDoc } from '../parser.js';
|
|
5
5
|
import { BindingElement, BindingPattern, CallSignatureDeclaration, ClassDeclaration, ClassExpression, ComputedPropertyName, ConditionalTypeNode, ConstructSignatureDeclaration, ConstructorDeclaration, ConstructorTypeNode, EnumDeclaration, EnumMember, ExportAssignment, ExportDeclaration, ExpressionWithTypeArguments, ExternalModuleReference, FileReference, ArrayTypeNode, ArrowFunction, BinaryExpression, TypeLiteralNode, UnionTypeNode, ElementAccessExpression, ExportSpecifier, FunctionDeclaration, FunctionExpression, FunctionTypeNode, ImportSpecifier, NodeVisitor, PropertyAccessExpression, QualifiedName, getArguments, GetAccessorDeclaration, HeritageClause, Identifier, ImportClause, ImportDeclaration, ImportEqualsDeclaration, ImportTypeNode, IndexSignatureDeclaration, InterfaceDeclaration, KeywordTypeNode, LiteralTypeNode, MappedTypeNode, MethodDeclaration, MethodSignatureDeclaration, ModuleBlock, ModuleDeclaration, NamedExports, NamedImports, NamespaceImport, NodeList, NumericLiteral, ParameterDeclaration, PrefixUnaryExpression, PrivateIdentifier, PropertyDeclaration, PropertySignatureDeclaration, JSDoc, JSDocText, SetAccessorDeclaration, SourceFile, StringLiteral, SyntaxList, TypeAliasDeclaration, TypeParameterDeclaration, VariableDeclaration, VariableStatement, getExpression, getHeritageClauses, getMembers, getInitializer, getModifiers, getName, getParameters, getSymbol, getText, getType, getTypeParameters, isDeclarationNode, } from '../ast.js';
|
|
6
|
-
import { isAmbientModule, isAnyImportOrReExport, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLiteralImportTypeNode, modifierToFlag, nodeIsMissing, nodeIsPresent, } from '../ast-utilities.js';
|
|
6
|
+
import { getHeritageClauseElementName, isAmbientModule, isAnyImportOrReExport, isFunctionLike, isGlobalScopeAugmentation, isInJSFile, isLiteralImportTypeNode, modifierToFlag, nodeIsMissing, nodeIsPresent, } from '../ast-utilities.js';
|
|
7
7
|
import { getAssignmentDeclarationKind, getCombinedModifierFlags, getCombinedNodeFlags, getElementOrPropertyAccessName, getThisContainer, isVariableDeclarationInitializedToRequire, getSourceFileOfNode, getSourceTextOfNode, hasDynamicName, hasSyntacticModifier, isEntityNameExpression, isExternalOrCommonJSModule, isStatic, } from '../binder-utilities.js';
|
|
8
8
|
import { getOutputPathsFor } from '../output-paths.js';
|
|
9
9
|
import { getDirectoryPath, normalizeSlashes } from '../path.js';
|
|
@@ -34,6 +34,8 @@ export class DeclarationTransformer extends Transformer {
|
|
|
34
34
|
expandoHosts;
|
|
35
35
|
/** The namespace members for the assigned properties of each function, by statement. */
|
|
36
36
|
expandoMembers;
|
|
37
|
+
/** Assigned properties of hosts that weren't visible when found, by host; written if the host becomes visible. */
|
|
38
|
+
deferredExpandoAssignments;
|
|
37
39
|
/** The `export =` for a CommonJS `module.exports = …`. */
|
|
38
40
|
cjsExportAssignment;
|
|
39
41
|
/** The exports for CommonJS `exports.x = …` assignments. */
|
|
@@ -61,6 +63,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
61
63
|
this.lateStatementReplacements = new Map();
|
|
62
64
|
this.expandoHosts = new Map();
|
|
63
65
|
this.expandoMembers = new Map();
|
|
66
|
+
this.deferredExpandoAssignments = new Map();
|
|
64
67
|
this.cjsExportAssignment = undefined;
|
|
65
68
|
this.cjsExportMembers = [];
|
|
66
69
|
this.cjsExportAssignmentName = undefined;
|
|
@@ -73,46 +76,46 @@ export class DeclarationTransformer extends Transformer {
|
|
|
73
76
|
}
|
|
74
77
|
visit(node) {
|
|
75
78
|
switch (node.kind) {
|
|
76
|
-
case
|
|
79
|
+
case 308 /* SyntaxKind.SourceFile */:
|
|
77
80
|
if (node instanceof SourceFile) {
|
|
78
81
|
const narrowed = node;
|
|
79
82
|
return this.visitSourceFile(narrowed);
|
|
80
83
|
}
|
|
81
84
|
break;
|
|
82
|
-
case
|
|
83
|
-
case
|
|
84
|
-
case
|
|
85
|
-
case
|
|
86
|
-
case
|
|
87
|
-
case
|
|
88
|
-
case
|
|
89
|
-
case
|
|
90
|
-
case
|
|
91
|
-
case
|
|
92
|
-
case
|
|
93
|
-
case
|
|
94
|
-
case
|
|
85
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
86
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
87
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
88
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
89
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
90
|
+
case 346 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
91
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
92
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
93
|
+
case 245 /* SyntaxKind.VariableStatement */:
|
|
94
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
95
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
96
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
97
|
+
case 279 /* SyntaxKind.ExportAssignment */:
|
|
95
98
|
return this.visitDeclarationStatement(node);
|
|
96
|
-
case
|
|
97
|
-
case
|
|
98
|
-
case
|
|
99
|
-
case
|
|
100
|
-
case
|
|
101
|
-
case
|
|
102
|
-
case
|
|
103
|
-
case
|
|
104
|
-
case
|
|
105
|
-
case
|
|
106
|
-
case
|
|
107
|
-
case
|
|
108
|
-
case
|
|
109
|
-
case
|
|
110
|
-
case
|
|
111
|
-
case
|
|
112
|
-
case
|
|
113
|
-
case
|
|
114
|
-
case
|
|
115
|
-
case
|
|
99
|
+
case 254 /* SyntaxKind.BreakStatement */:
|
|
100
|
+
case 253 /* SyntaxKind.ContinueStatement */:
|
|
101
|
+
case 261 /* SyntaxKind.DebuggerStatement */:
|
|
102
|
+
case 248 /* SyntaxKind.DoStatement */:
|
|
103
|
+
case 244 /* SyntaxKind.EmptyStatement */:
|
|
104
|
+
case 251 /* SyntaxKind.ForInStatement */:
|
|
105
|
+
case 252 /* SyntaxKind.ForOfStatement */:
|
|
106
|
+
case 250 /* SyntaxKind.ForStatement */:
|
|
107
|
+
case 247 /* SyntaxKind.IfStatement */:
|
|
108
|
+
case 258 /* SyntaxKind.LabeledStatement */:
|
|
109
|
+
case 255 /* SyntaxKind.ReturnStatement */:
|
|
110
|
+
case 257 /* SyntaxKind.SwitchStatement */:
|
|
111
|
+
case 259 /* SyntaxKind.ThrowStatement */:
|
|
112
|
+
case 260 /* SyntaxKind.TryStatement */:
|
|
113
|
+
case 249 /* SyntaxKind.WhileStatement */:
|
|
114
|
+
case 256 /* SyntaxKind.WithStatement */:
|
|
115
|
+
case 348 /* SyntaxKind.NotEmittedStatement */:
|
|
116
|
+
case 243 /* SyntaxKind.Block */:
|
|
117
|
+
case 284 /* SyntaxKind.MissingDeclaration */:
|
|
118
|
+
case 246 /* SyntaxKind.ExpressionStatement */:
|
|
116
119
|
return undefined;
|
|
117
120
|
}
|
|
118
121
|
return this.visitDeclarationSubtree(node);
|
|
@@ -130,6 +133,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
130
133
|
this.lateStatementReplacements = new Map();
|
|
131
134
|
this.expandoHosts.clear();
|
|
132
135
|
this.expandoMembers.clear();
|
|
136
|
+
this.deferredExpandoAssignments.clear();
|
|
133
137
|
this.witnessedCjsExports.clear();
|
|
134
138
|
this.cjsExportAssignment = undefined;
|
|
135
139
|
this.cjsExportAssignmentName = undefined;
|
|
@@ -173,7 +177,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
173
177
|
}
|
|
174
178
|
originalSourceFile(file) {
|
|
175
179
|
const original = this.context.mostOriginal(file);
|
|
176
|
-
if (original === undefined || original.kind !==
|
|
180
|
+
if (original === undefined || original.kind !== 308 /* SyntaxKind.SourceFile */)
|
|
177
181
|
return file;
|
|
178
182
|
return original;
|
|
179
183
|
}
|
|
@@ -195,7 +199,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
195
199
|
if (exportEquals === undefined || declarationCount(exportEquals) <= 1)
|
|
196
200
|
return false;
|
|
197
201
|
for (const declaration of getDeclarations(exportEquals))
|
|
198
|
-
this.tracker.addDiagnostic(createDiagnosticForNode(declaration,
|
|
202
|
+
this.tracker.addDiagnostic(createDiagnosticForNode(declaration, 1524 /* Diagnostics.Multiple_module_exports_assignments_cannot_be_serialized_for_declaration_emit */, []));
|
|
199
203
|
return true;
|
|
200
204
|
}
|
|
201
205
|
createEmptyExports() {
|
|
@@ -234,7 +238,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
234
238
|
while (tracker.lateMarkedStatements.length > 0) {
|
|
235
239
|
const next = tracker.lateMarkedStatements.shift();
|
|
236
240
|
const saveNeedsDeclare = this.needsDeclare;
|
|
237
|
-
this.needsDeclare = next.parent !== undefined && next.parent.kind ===
|
|
241
|
+
this.needsDeclare = next.parent !== undefined && next.parent.kind === 308 /* SyntaxKind.SourceFile */;
|
|
238
242
|
const result = this.transformTopLevelDeclaration(next);
|
|
239
243
|
this.needsDeclare = saveNeedsDeclare;
|
|
240
244
|
this.lateStatementReplacements.set(this.context.mostOriginal(next), result);
|
|
@@ -253,7 +257,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
253
257
|
const replacement = this.lateStatementReplacements.get(original);
|
|
254
258
|
if (replacement === undefined)
|
|
255
259
|
continue;
|
|
256
|
-
const atTopLevel = statement.parent !== undefined && statement.parent.kind ===
|
|
260
|
+
const atTopLevel = statement.parent !== undefined && statement.parent.kind === 308 /* SyntaxKind.SourceFile */;
|
|
257
261
|
if (replacement instanceof SyntaxList) {
|
|
258
262
|
if (!this.needsScopeFixMarker || !this.resultHasExternalModuleIndicator)
|
|
259
263
|
for (const child of replacement.children) {
|
|
@@ -281,10 +285,10 @@ export class DeclarationTransformer extends Transformer {
|
|
|
281
285
|
const scope = new DiagnosticScope(tracker.diagnosticContext, tracker.errorNameNode, this.suppressNewDiagnosticContexts);
|
|
282
286
|
if (canProduceDiagnostics(input) && !this.suppressNewDiagnosticContexts)
|
|
283
287
|
tracker.diagnosticContext = declarationContext(input);
|
|
284
|
-
if ((input.kind ===
|
|
288
|
+
if ((input.kind === 189 /* SyntaxKind.TypeLiteral */ || input.kind === 202 /* SyntaxKind.MappedType */) &&
|
|
285
289
|
input.parent !== undefined &&
|
|
286
|
-
input.parent.kind !==
|
|
287
|
-
input.parent.kind !==
|
|
290
|
+
input.parent.kind !== 267 /* SyntaxKind.TypeAliasDeclaration */ &&
|
|
291
|
+
input.parent.kind !== 346 /* SyntaxKind.JSTypeAliasDeclaration */)
|
|
288
292
|
this.suppressNewDiagnosticContexts = true;
|
|
289
293
|
return scope;
|
|
290
294
|
}
|
|
@@ -309,13 +313,13 @@ export class DeclarationTransformer extends Transformer {
|
|
|
309
313
|
// Computed names that aren't literal types can't be checked without types.
|
|
310
314
|
if (!this.resolver.isDefinitelyReferenceToGlobalSymbolObject(expression)) {
|
|
311
315
|
const parentKind = input.parent.kind;
|
|
312
|
-
if (parentKind ===
|
|
313
|
-
this.tracker.addDiagnostic(createDiagnosticForNode(input,
|
|
316
|
+
if (parentKind === 265 /* SyntaxKind.ClassDeclaration */ || parentKind === 212 /* SyntaxKind.ObjectLiteralExpression */) {
|
|
317
|
+
this.tracker.addDiagnostic(createDiagnosticForNode(input, 1822 /* Diagnostics.Computed_property_names_on_class_or_object_literals_cannot_be_inferred_with_isolatedDeclarations */, []));
|
|
314
318
|
return undefined;
|
|
315
319
|
}
|
|
316
|
-
if ((parentKind ===
|
|
320
|
+
if ((parentKind === 266 /* SyntaxKind.InterfaceDeclaration */ || parentKind === 189 /* SyntaxKind.TypeLiteral */) &&
|
|
317
321
|
!isEntityNameExpression(expression, false)) {
|
|
318
|
-
this.tracker.addDiagnostic(createDiagnosticForNode(input,
|
|
322
|
+
this.tracker.addDiagnostic(createDiagnosticForNode(input, 1799 /* Diagnostics.Computed_properties_must_be_number_or_string_literals_variables_or_dotted_expressions_with_isolatedDeclarations */, []));
|
|
319
323
|
return undefined;
|
|
320
324
|
}
|
|
321
325
|
}
|
|
@@ -327,7 +331,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
327
331
|
// Implementations of overloads are elided.
|
|
328
332
|
if (isFunctionLike(input) && this.resolver.isImplementationOfOverload(input))
|
|
329
333
|
return undefined;
|
|
330
|
-
if (input.kind ===
|
|
334
|
+
if (input.kind === 242 /* SyntaxKind.SemicolonClassElement */)
|
|
331
335
|
return undefined;
|
|
332
336
|
if (input instanceof HeritageClause) {
|
|
333
337
|
const types = input.types.nodes;
|
|
@@ -348,152 +352,159 @@ export class DeclarationTransformer extends Transformer {
|
|
|
348
352
|
}
|
|
349
353
|
transformDeclarationSubtree(input) {
|
|
350
354
|
switch (input.kind) {
|
|
351
|
-
case
|
|
355
|
+
case 202 /* SyntaxKind.MappedType */:
|
|
352
356
|
if (input instanceof MappedTypeNode) {
|
|
353
357
|
const narrowed = input;
|
|
354
358
|
return this.transformMappedType(narrowed);
|
|
355
359
|
}
|
|
356
360
|
break;
|
|
357
|
-
case
|
|
361
|
+
case 300 /* SyntaxKind.HeritageClause */:
|
|
358
362
|
if (input instanceof HeritageClause) {
|
|
359
363
|
const narrowed = input;
|
|
360
364
|
return this.transformHeritageClause(narrowed);
|
|
361
365
|
}
|
|
362
366
|
break;
|
|
363
|
-
case
|
|
367
|
+
case 175 /* SyntaxKind.MethodSignature */:
|
|
364
368
|
if (input instanceof MethodSignatureDeclaration) {
|
|
365
369
|
const narrowed = input;
|
|
366
370
|
return this.transformMethodSignature(narrowed);
|
|
367
371
|
}
|
|
368
372
|
break;
|
|
369
|
-
case
|
|
373
|
+
case 176 /* SyntaxKind.MethodDeclaration */:
|
|
370
374
|
if (input instanceof MethodDeclaration) {
|
|
371
375
|
const narrowed = input;
|
|
372
376
|
return this.transformMethodDeclaration(narrowed);
|
|
373
377
|
}
|
|
374
378
|
break;
|
|
375
|
-
case
|
|
379
|
+
case 182 /* SyntaxKind.ConstructSignature */:
|
|
376
380
|
if (input instanceof ConstructSignatureDeclaration) {
|
|
377
381
|
const narrowed = input;
|
|
378
382
|
return this.transformConstructSignature(narrowed);
|
|
379
383
|
}
|
|
380
384
|
break;
|
|
381
|
-
case
|
|
385
|
+
case 178 /* SyntaxKind.Constructor */:
|
|
382
386
|
if (input instanceof ConstructorDeclaration) {
|
|
383
387
|
const narrowed = input;
|
|
384
388
|
return this.transformConstructor(narrowed);
|
|
385
389
|
}
|
|
386
390
|
break;
|
|
387
|
-
case
|
|
391
|
+
case 179 /* SyntaxKind.GetAccessor */:
|
|
388
392
|
if (input instanceof GetAccessorDeclaration) {
|
|
389
393
|
const narrowed = input;
|
|
390
394
|
return this.transformGetAccessor(narrowed);
|
|
391
395
|
}
|
|
392
396
|
break;
|
|
393
|
-
case
|
|
397
|
+
case 180 /* SyntaxKind.SetAccessor */:
|
|
394
398
|
if (input instanceof SetAccessorDeclaration) {
|
|
395
399
|
const narrowed = input;
|
|
396
400
|
return this.transformSetAccessor(narrowed);
|
|
397
401
|
}
|
|
398
402
|
break;
|
|
399
|
-
case
|
|
403
|
+
case 174 /* SyntaxKind.PropertyDeclaration */:
|
|
400
404
|
if (input instanceof PropertyDeclaration) {
|
|
401
405
|
const narrowed = input;
|
|
402
406
|
return this.transformPropertyDeclaration(narrowed);
|
|
403
407
|
}
|
|
404
408
|
break;
|
|
405
|
-
case
|
|
409
|
+
case 173 /* SyntaxKind.PropertySignature */:
|
|
406
410
|
if (input instanceof PropertySignatureDeclaration) {
|
|
407
411
|
const narrowed = input;
|
|
408
412
|
return this.transformPropertySignature(narrowed);
|
|
409
413
|
}
|
|
410
414
|
break;
|
|
411
|
-
case
|
|
415
|
+
case 181 /* SyntaxKind.CallSignature */:
|
|
412
416
|
if (input instanceof CallSignatureDeclaration) {
|
|
413
417
|
const narrowed = input;
|
|
414
418
|
return this.transformCallSignature(narrowed);
|
|
415
419
|
}
|
|
416
420
|
break;
|
|
417
|
-
case
|
|
421
|
+
case 183 /* SyntaxKind.IndexSignature */:
|
|
418
422
|
if (input instanceof IndexSignatureDeclaration) {
|
|
419
423
|
const narrowed = input;
|
|
420
424
|
return this.transformIndexSignature(narrowed);
|
|
421
425
|
}
|
|
422
426
|
break;
|
|
423
|
-
case
|
|
427
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
424
428
|
if (input instanceof VariableDeclaration) {
|
|
425
429
|
const narrowed = input;
|
|
426
430
|
return this.transformVariableDeclaration(narrowed);
|
|
427
431
|
}
|
|
428
432
|
break;
|
|
429
|
-
case
|
|
433
|
+
case 170 /* SyntaxKind.TypeParameter */:
|
|
430
434
|
if (input instanceof TypeParameterDeclaration) {
|
|
431
435
|
const narrowed = input;
|
|
432
436
|
return this.transformTypeParameter(narrowed);
|
|
433
437
|
}
|
|
434
438
|
break;
|
|
435
|
-
case
|
|
439
|
+
case 235 /* SyntaxKind.ExpressionWithTypeArguments */: {
|
|
436
440
|
const expression = input.expression;
|
|
437
441
|
if (isEntityName(expression) || isEntityNameExpression(expression, false))
|
|
438
442
|
this.checkEntityNameVisibility(expression, this.enclosingDeclaration);
|
|
439
443
|
return this.visitEachChild(input);
|
|
440
444
|
}
|
|
441
|
-
case
|
|
445
|
+
case 185 /* SyntaxKind.TypeReference */:
|
|
442
446
|
this.checkEntityNameVisibility(input.typeName, this.enclosingDeclaration);
|
|
443
447
|
return this.visitEachChild(input);
|
|
444
|
-
case
|
|
448
|
+
case 196 /* SyntaxKind.ConditionalType */:
|
|
445
449
|
if (input instanceof ConditionalTypeNode) {
|
|
446
450
|
const narrowed = input;
|
|
447
451
|
return this.transformConditionalType(narrowed);
|
|
448
452
|
}
|
|
449
453
|
break;
|
|
450
|
-
case
|
|
454
|
+
case 186 /* SyntaxKind.FunctionType */:
|
|
451
455
|
if (input instanceof FunctionTypeNode) {
|
|
452
456
|
const narrowed = input;
|
|
453
457
|
return this.transformFunctionType(narrowed);
|
|
454
458
|
}
|
|
455
459
|
break;
|
|
456
|
-
case
|
|
460
|
+
case 187 /* SyntaxKind.ConstructorType */:
|
|
457
461
|
if (input instanceof ConstructorTypeNode) {
|
|
458
462
|
const narrowed = input;
|
|
459
463
|
return this.transformConstructorType(narrowed);
|
|
460
464
|
}
|
|
461
465
|
break;
|
|
462
|
-
case
|
|
466
|
+
case 207 /* SyntaxKind.ImportType */:
|
|
463
467
|
if (input instanceof ImportTypeNode) {
|
|
464
468
|
const narrowed = input;
|
|
465
469
|
return this.transformImportType(narrowed);
|
|
466
470
|
}
|
|
467
471
|
break;
|
|
468
|
-
case
|
|
472
|
+
case 188 /* SyntaxKind.TypeQuery */:
|
|
469
473
|
this.checkEntityNameVisibility(input.exprName, this.enclosingDeclaration);
|
|
470
474
|
return this.visitEachChild(input);
|
|
471
|
-
case
|
|
475
|
+
case 168 /* SyntaxKind.QualifiedName */: {
|
|
476
|
+
// `typeof this.#x`: the private member isn't in the declaration output.
|
|
477
|
+
const right = input.right;
|
|
478
|
+
if (right.kind === 80 /* SyntaxKind.PrivateIdentifier */)
|
|
479
|
+
this.tracker.addDiagnostic(createDiagnosticForNode(input, 1752 /* Diagnostics.Declaration_emit_elides_private_members_but_0_refers_to_a_private_member_Write_an_explicit_type_here */, [getText(right)]));
|
|
480
|
+
return this.visitEachChild(input);
|
|
481
|
+
}
|
|
482
|
+
case 191 /* SyntaxKind.TupleType */: {
|
|
472
483
|
const result = this.visitEachChild(input);
|
|
473
484
|
if (isOriginalNodeSingleLine(this.context, input))
|
|
474
485
|
this.context.addEmitFlags(result, 1 /* EmitFlags.SingleLine */);
|
|
475
486
|
return result;
|
|
476
487
|
}
|
|
477
|
-
case
|
|
488
|
+
case 309 /* SyntaxKind.JSDocTypeExpression */:
|
|
478
489
|
return this.visitNode(input.type);
|
|
479
|
-
case
|
|
490
|
+
case 311 /* SyntaxKind.JSDocAllType */:
|
|
480
491
|
return this.replaceWith(input, this.keyword(132 /* SyntaxKind.AnyKeyword */));
|
|
481
|
-
case
|
|
492
|
+
case 312 /* SyntaxKind.JSDocNullableType */:
|
|
482
493
|
// `?T` is `T | null`.
|
|
483
494
|
return this.replaceWith(input, this.createUnion(this.visitNode(input.type), this.factory.created(new LiteralTypeNode(this.factory.createKeywordExpression(105 /* SyntaxKind.NullKeyword */)))));
|
|
484
|
-
case
|
|
495
|
+
case 313 /* SyntaxKind.JSDocNonNullableType */:
|
|
485
496
|
return this.visitNode(input.type);
|
|
486
|
-
case
|
|
497
|
+
case 314 /* SyntaxKind.JSDocOptionalType */:
|
|
487
498
|
// `T=` is `T | undefined`.
|
|
488
499
|
return this.replaceWith(input, this.createUnion(this.visitNode(input.type), this.keyword(157 /* SyntaxKind.UndefinedKeyword */)));
|
|
489
|
-
case
|
|
500
|
+
case 315 /* SyntaxKind.JSDocVariadicType */:
|
|
490
501
|
// `...T` is `T[]`.
|
|
491
502
|
return this.replaceWith(input, this.factory.created(new ArrayTypeNode(this.visitNode(input.type))));
|
|
492
|
-
case
|
|
503
|
+
case 318 /* SyntaxKind.JSDocTypeLiteral */: {
|
|
493
504
|
const members = this.visitArray(input.jsdocPropertyTags ?? []);
|
|
494
505
|
return this.replaceWith(input, this.factory.created(new TypeLiteralNode(this.factory.createNodeList(members))));
|
|
495
506
|
}
|
|
496
|
-
case
|
|
507
|
+
case 341 /* SyntaxKind.JSDocPropertyTag */: {
|
|
497
508
|
const tag = input;
|
|
498
509
|
const type = tag.typeExpression === undefined ? undefined : this.visitNode(tag.typeExpression);
|
|
499
510
|
return this.replaceWith(input, this.factory.created(new PropertySignatureDeclaration(undefined, this.visitNode(tag.name), undefined, type, undefined)));
|
|
@@ -536,9 +547,12 @@ export class DeclarationTransformer extends Transformer {
|
|
|
536
547
|
const types = clause.types.nodes;
|
|
537
548
|
const retained = [];
|
|
538
549
|
for (const type of types) {
|
|
539
|
-
const
|
|
540
|
-
if (
|
|
541
|
-
(
|
|
550
|
+
const name = getHeritageClauseElementName(type);
|
|
551
|
+
if (name.kind === 168 /* SyntaxKind.QualifiedName */ ||
|
|
552
|
+
isEntityNameExpression(name, false) ||
|
|
553
|
+
(clause.token === 95 /* SyntaxKind.ExtendsKeyword */ &&
|
|
554
|
+
type.kind === 235 /* SyntaxKind.ExpressionWithTypeArguments */ &&
|
|
555
|
+
name.kind === 105 /* SyntaxKind.NullKeyword */))
|
|
542
556
|
retained.push(type);
|
|
543
557
|
}
|
|
544
558
|
if (retained.length === 0)
|
|
@@ -573,7 +587,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
573
587
|
// Type parameters of private methods lose their constraints and defaults.
|
|
574
588
|
const parent = input.parent;
|
|
575
589
|
if (parent !== undefined &&
|
|
576
|
-
parent.kind ===
|
|
590
|
+
parent.kind === 176 /* SyntaxKind.MethodDeclaration */ &&
|
|
577
591
|
this.isPrivate(parent) &&
|
|
578
592
|
(input.defaultType !== undefined || input.constraint !== undefined))
|
|
579
593
|
return this.factory.updateTypeParameterDeclaration(input, input.modifiers, input.name, undefined, input.expression, undefined);
|
|
@@ -585,11 +599,12 @@ export class DeclarationTransformer extends Transformer {
|
|
|
585
599
|
file.commonJSModuleIndicator !== undefined &&
|
|
586
600
|
isVariableDeclarationInitializedToRequire(input))
|
|
587
601
|
return this.transformCjsRequireVariableDeclaration(input);
|
|
588
|
-
|
|
602
|
+
// A binding pattern with initializers becomes a declaration per name; without them it stays.
|
|
603
|
+
if (input.name instanceof BindingPattern && hasAnyBindingInitializers(input.name))
|
|
589
604
|
return this.recreateBindingPattern(input.name);
|
|
590
605
|
// Variable types don't enter new diagnostic contexts.
|
|
591
606
|
this.suppressNewDiagnosticContexts = true;
|
|
592
|
-
return this.factory.updateVariableDeclaration(input, input.name, undefined, this.ensureType(input, false), this.ensureNoInitializer(input));
|
|
607
|
+
return this.factory.updateVariableDeclaration(input, this.visitBindingName(input.name), undefined, this.ensureType(input, false), this.ensureNoInitializer(input));
|
|
593
608
|
}
|
|
594
609
|
recreateBindingPattern(pattern) {
|
|
595
610
|
const results = [];
|
|
@@ -672,7 +687,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
672
687
|
if (thisParameter !== undefined)
|
|
673
688
|
params.push(this.ensureParameterNode(thisParameter));
|
|
674
689
|
}
|
|
675
|
-
if (input.kind ===
|
|
690
|
+
if (input.kind === 180 /* SyntaxKind.SetAccessor */) {
|
|
676
691
|
let valueParameter = undefined;
|
|
677
692
|
if (!isPrivate) {
|
|
678
693
|
if (params.length === 1 && parameters.length >= 2)
|
|
@@ -697,7 +712,12 @@ export class DeclarationTransformer extends Transformer {
|
|
|
697
712
|
const symbol = getSymbol(input);
|
|
698
713
|
if (symbol !== undefined && declarationCount(symbol) > 0 && symbol.declaration !== input)
|
|
699
714
|
return undefined;
|
|
700
|
-
|
|
715
|
+
// A method signature becomes a property signature, a method a property declaration.
|
|
716
|
+
let result;
|
|
717
|
+
if (input.kind === 175 /* SyntaxKind.MethodSignature */)
|
|
718
|
+
result = this.factory.created(new PropertySignatureDeclaration(this.ensureModifiers(input), getName(input), undefined, undefined, undefined));
|
|
719
|
+
else
|
|
720
|
+
result = this.factory.created(new PropertyDeclaration(this.ensureModifiers(input), getName(input), undefined, undefined, undefined));
|
|
701
721
|
this.context.assignCommentRange(result, input);
|
|
702
722
|
return result;
|
|
703
723
|
}
|
|
@@ -722,10 +742,10 @@ export class DeclarationTransformer extends Transformer {
|
|
|
722
742
|
if (this.shouldStripInternal(input))
|
|
723
743
|
return undefined;
|
|
724
744
|
if (input instanceof ExportDeclaration) {
|
|
725
|
-
if (input.parent !== undefined && input.parent.kind ===
|
|
745
|
+
if (input.parent !== undefined && input.parent.kind === 308 /* SyntaxKind.SourceFile */)
|
|
726
746
|
this.resultHasExternalModuleIndicator = true;
|
|
727
747
|
this.resultHasScopeMarker = true;
|
|
728
|
-
return this.factory.updateExportDeclaration(input, input.modifiers, input.isTypeOnly, input.exportClause, this.rewriteModuleSpecifier(input, input.moduleSpecifier),
|
|
748
|
+
return this.factory.updateExportDeclaration(input, input.modifiers, input.isTypeOnly, input.exportClause, this.rewriteModuleSpecifier(input, input.moduleSpecifier), input.attributes);
|
|
729
749
|
}
|
|
730
750
|
if (input instanceof ExportAssignment)
|
|
731
751
|
return this.transformExportAssignment(input, input, input.expression, input.isExportEquals);
|
|
@@ -737,33 +757,37 @@ export class DeclarationTransformer extends Transformer {
|
|
|
737
757
|
}
|
|
738
758
|
/** `export =`, `export default` or `module.exports =` of `expression`. */
|
|
739
759
|
transformExportAssignment(input, assignment, expression, isExportEquals) {
|
|
740
|
-
if (input.parent !== undefined && input.parent.kind ===
|
|
760
|
+
if (input.parent !== undefined && input.parent.kind === 308 /* SyntaxKind.SourceFile */)
|
|
741
761
|
this.resultHasExternalModuleIndicator = true;
|
|
742
762
|
this.resultHasScopeMarker = true;
|
|
743
763
|
if (expression instanceof Identifier &&
|
|
744
764
|
input.parent !== undefined &&
|
|
745
|
-
(input.parent.kind ===
|
|
765
|
+
(input.parent.kind === 308 /* SyntaxKind.SourceFile */ || input.parent.kind === 270 /* SyntaxKind.ModuleBlock */)) {
|
|
746
766
|
const result = this.factory.created(new ExportAssignment(undefined, isExportEquals, undefined, expression));
|
|
767
|
+
this.context.assignSourceMapRange(result, input);
|
|
747
768
|
this.context.assignCommentRange(result, input);
|
|
748
769
|
return result;
|
|
749
770
|
}
|
|
771
|
+
// Types the default export can't name are reported for it, as class and function declarations too.
|
|
772
|
+
const tracker = this.tracker;
|
|
773
|
+
tracker.diagnosticContext = new DiagnosticContext(3 /* DiagnosticContextKind.DefaultExport */, input, undefined);
|
|
774
|
+
tracker.pushErrorFallbackNode(assignment);
|
|
750
775
|
const unwrapped = skipOuterExpressions(expression);
|
|
751
776
|
const name = this.getNameOfExportedExpression(unwrapped, isExportEquals);
|
|
752
777
|
// Class and function expressions become declarations.
|
|
753
778
|
if (unwrapped instanceof ClassExpression || isFunctionLike(unwrapped)) {
|
|
754
779
|
const declaration = unwrapped instanceof ClassExpression
|
|
755
780
|
? this.transformClassExpressionToDeclaration(unwrapped, name, this.declareModifiers())
|
|
756
|
-
: this.transformFunctionLikeToDeclaration(unwrapped, name, this.declareModifiers());
|
|
781
|
+
: this.transformFunctionLikeToDeclaration(unwrapped, name, this.declareModifiers(), getType(assignment));
|
|
782
|
+
tracker.popErrorFallbackNode();
|
|
757
783
|
this.context.assignCommentRange(declaration, input);
|
|
758
784
|
const exportAssignment = this.factory.created(new ExportAssignment(undefined, isExportEquals, undefined, name));
|
|
785
|
+
this.context.assignSourceMapRange(exportAssignment, input);
|
|
759
786
|
this.context.addEmitFlags(exportAssignment, 384 /* EmitFlags.NoComments */);
|
|
760
787
|
return this.factory.createSyntaxList([exportAssignment, declaration]);
|
|
761
788
|
}
|
|
762
789
|
// Other expressions are written as a `_default` variable with the expression's type.
|
|
763
|
-
const tracker = this.tracker;
|
|
764
|
-
tracker.diagnosticContext = new DiagnosticContext(3 /* DiagnosticContextKind.DefaultExport */, input, undefined);
|
|
765
790
|
this.cjsExportAssignmentName = name;
|
|
766
|
-
tracker.pushErrorFallbackNode(assignment);
|
|
767
791
|
let initializer = undefined;
|
|
768
792
|
if (isPrimitiveLiteralValue(skipParenthesesOnly(expression), true))
|
|
769
793
|
initializer = this.resolver.createLiteralConstValue(this.context, this.parseNode(assignment), tracker);
|
|
@@ -772,15 +796,21 @@ export class DeclarationTransformer extends Transformer {
|
|
|
772
796
|
tracker.popErrorFallbackNode();
|
|
773
797
|
const statement = this.createConstStatement(declaration);
|
|
774
798
|
const exportAssignment = this.factory.created(new ExportAssignment(undefined, isExportEquals, undefined, name));
|
|
799
|
+
this.context.assignSourceMapRange(exportAssignment, input);
|
|
775
800
|
this.context.assignCommentRange(statement, input);
|
|
776
801
|
return this.factory.createSyntaxList([statement, exportAssignment]);
|
|
777
802
|
}
|
|
778
803
|
createConstStatement(declaration) {
|
|
779
804
|
return this.factory.createVariableStatement(this.declareModifiers(), this.factory.createVariableDeclarationList(this.factory.createNodeList([declaration]), 2 /* NodeFlags.Const */));
|
|
780
805
|
}
|
|
781
|
-
transformFunctionLikeToDeclaration(fn, name, modifiers) {
|
|
782
|
-
|
|
783
|
-
|
|
806
|
+
transformFunctionLikeToDeclaration(fn, name, modifiers, fullSignatureType) {
|
|
807
|
+
// A JSDoc signature, of the function or of the assignment, is reused as the type of a `const`.
|
|
808
|
+
const fullSignature = getFullSignature(fn) ?? fullSignatureType;
|
|
809
|
+
if (fullSignature !== undefined)
|
|
810
|
+
return this.factory.createVariableStatement(modifiers, this.factory.createVariableDeclarationList(this.factory.createNodeList([
|
|
811
|
+
this.factory.createVariableDeclaration(name, undefined, this.visitNode(fullSignature), undefined),
|
|
812
|
+
]), 2 /* NodeFlags.Const */));
|
|
813
|
+
return this.factory.created(new FunctionDeclaration(modifiers, undefined, name, this.ensureTypeParams(fn, getTypeParameters(fn)), this.updateParamList(fn, getParameters(fn)), this.ensureType(fn, false), undefined, undefined));
|
|
784
814
|
}
|
|
785
815
|
/** A class expression as a declaration, for `export default (class {})` and CommonJS exports. */
|
|
786
816
|
transformClassExpressionToDeclaration(classExpression, name, modifiers) {
|
|
@@ -816,7 +846,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
816
846
|
/** The name of a named function or class expression, unique if it would shadow something. */
|
|
817
847
|
tryGetNameOfAssignedExpression(expression) {
|
|
818
848
|
let text = '';
|
|
819
|
-
if (expression.kind !==
|
|
849
|
+
if (expression.kind !== 213 /* SyntaxKind.PropertyAccessExpression */) {
|
|
820
850
|
const name = getName(expression);
|
|
821
851
|
if (name instanceof Identifier)
|
|
822
852
|
text = name.text;
|
|
@@ -832,15 +862,10 @@ export class DeclarationTransformer extends Transformer {
|
|
|
832
862
|
rewriteModuleSpecifier(parent, input) {
|
|
833
863
|
if (input === undefined)
|
|
834
864
|
return undefined;
|
|
835
|
-
if (parent.kind !==
|
|
865
|
+
if (parent.kind !== 269 /* SyntaxKind.ModuleDeclaration */ && parent.kind !== 207 /* SyntaxKind.ImportType */)
|
|
836
866
|
this.resultHasExternalModuleIndicator = true;
|
|
837
867
|
return input;
|
|
838
868
|
}
|
|
839
|
-
tryGetResolutionModeOverride(node) {
|
|
840
|
-
if (node === undefined)
|
|
841
|
-
return undefined;
|
|
842
|
-
return this.resolver.getResolutionModeOverride(node) !== undefined ? node : undefined;
|
|
843
|
-
}
|
|
844
869
|
/** The replacement statements for a direct child of a source file or module block. */
|
|
845
870
|
transformTopLevelDeclaration(input) {
|
|
846
871
|
if (input === undefined)
|
|
@@ -863,9 +888,9 @@ export class DeclarationTransformer extends Transformer {
|
|
|
863
888
|
if (input instanceof ImportDeclaration) {
|
|
864
889
|
const result = this.transformImportDeclaration(input);
|
|
865
890
|
// `import x = require()` in JavaScript is written as an import declaration.
|
|
866
|
-
if (result !== undefined && result.kind !==
|
|
891
|
+
if (result !== undefined && result.kind !== 274 /* SyntaxKind.ImportDeclaration */) {
|
|
867
892
|
// A copy of the declaration, as tsgo's clone: with its position and emit node.
|
|
868
|
-
const clone = this.factory.created(new ImportDeclaration(
|
|
893
|
+
const clone = this.factory.created(new ImportDeclaration(274 /* SyntaxKind.ImportDeclaration */, result.modifiers, result.importClause, result.moduleSpecifier, result.attributes));
|
|
869
894
|
clone.pos = result.pos;
|
|
870
895
|
clone.end = result.end;
|
|
871
896
|
this.context.setOriginal(clone, result);
|
|
@@ -878,7 +903,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
878
903
|
if (isFunctionLike(input) && this.resolver.isImplementationOfOverload(input))
|
|
879
904
|
return undefined;
|
|
880
905
|
const original = this.context.mostOriginal(input);
|
|
881
|
-
if (this.expandoHosts.has(original))
|
|
906
|
+
if (this.expandoHosts.has(original) || this.deferredExpandoAssignments.has(original))
|
|
882
907
|
return this.createFullExpandoBlock(original);
|
|
883
908
|
const previousEnclosingDeclaration = this.enclosingDeclaration;
|
|
884
909
|
if (isEnclosingDeclaration(input))
|
|
@@ -890,44 +915,44 @@ export class DeclarationTransformer extends Transformer {
|
|
|
890
915
|
const saveNeedsDeclare = this.needsDeclare;
|
|
891
916
|
let result = undefined;
|
|
892
917
|
switch (input.kind) {
|
|
893
|
-
case
|
|
894
|
-
case
|
|
918
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
919
|
+
case 346 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
895
920
|
if (input instanceof TypeAliasDeclaration) {
|
|
896
921
|
const narrowed = input;
|
|
897
922
|
result = this.transformTypeAlias(narrowed);
|
|
898
923
|
}
|
|
899
924
|
break;
|
|
900
|
-
case
|
|
925
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
901
926
|
if (input instanceof InterfaceDeclaration) {
|
|
902
927
|
const narrowed = input;
|
|
903
928
|
result = this.transformInterface(narrowed);
|
|
904
929
|
}
|
|
905
930
|
break;
|
|
906
|
-
case
|
|
931
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
907
932
|
if (input instanceof FunctionDeclaration) {
|
|
908
933
|
const narrowed = input;
|
|
909
934
|
result = this.transformFunctionDeclaration(narrowed);
|
|
910
935
|
}
|
|
911
936
|
break;
|
|
912
|
-
case
|
|
937
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
913
938
|
if (input instanceof ModuleDeclaration) {
|
|
914
939
|
const narrowed = input;
|
|
915
940
|
result = this.transformModuleDeclaration(narrowed);
|
|
916
941
|
}
|
|
917
942
|
break;
|
|
918
|
-
case
|
|
943
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
919
944
|
if (input instanceof ClassDeclaration) {
|
|
920
945
|
const narrowed = input;
|
|
921
946
|
result = this.transformClassDeclaration(narrowed);
|
|
922
947
|
}
|
|
923
948
|
break;
|
|
924
|
-
case
|
|
949
|
+
case 245 /* SyntaxKind.VariableStatement */:
|
|
925
950
|
if (input instanceof VariableStatement) {
|
|
926
951
|
const narrowed = input;
|
|
927
952
|
result = this.transformVariableStatement(narrowed);
|
|
928
953
|
}
|
|
929
954
|
break;
|
|
930
|
-
case
|
|
955
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
931
956
|
if (input instanceof EnumDeclaration) {
|
|
932
957
|
const narrowed = input;
|
|
933
958
|
result = this.transformEnumDeclaration(narrowed);
|
|
@@ -944,7 +969,9 @@ export class DeclarationTransformer extends Transformer {
|
|
|
944
969
|
}
|
|
945
970
|
transformTypeAlias(input) {
|
|
946
971
|
this.needsDeclare = false;
|
|
947
|
-
return this.factory.updateTypeAliasDeclaration(input, this.ensureModifiers(input), input.name, this.visitNodes(input.typeParameters),
|
|
972
|
+
return this.factory.updateTypeAliasDeclaration(input, this.ensureModifiers(input), input.name, this.visitNodes(input.typeParameters),
|
|
973
|
+
// stripInternal can elide an `@internal` type on the right; it falls back to `any`, as index signatures do.
|
|
974
|
+
this.visitNode(input.type) ?? this.keyword(132 /* SyntaxKind.AnyKeyword */));
|
|
948
975
|
}
|
|
949
976
|
transformInterface(input) {
|
|
950
977
|
return this.factory.updateInterfaceDeclaration(input, this.ensureModifiers(input), input.name, this.visitNodes(input.typeParameters), this.visitNodes(input.heritageClauses), this.visitNodes(input.members));
|
|
@@ -959,6 +986,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
959
986
|
const saveNeedsDeclare = this.needsDeclare;
|
|
960
987
|
this.needsDeclare = false;
|
|
961
988
|
const body = input.body;
|
|
989
|
+
const attributes = this.visitNode(input.attributes);
|
|
962
990
|
let keyword = input.keyword;
|
|
963
991
|
if (keyword !== 162 /* SyntaxKind.GlobalKeyword */ && !(input.name instanceof StringLiteral))
|
|
964
992
|
keyword = 145 /* SyntaxKind.NamespaceKeyword */;
|
|
@@ -987,7 +1015,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
987
1015
|
this.needsDeclare = saveNeedsDeclare;
|
|
988
1016
|
this.needsScopeFixMarker = oldNeedsScopeFix;
|
|
989
1017
|
this.resultHasScopeMarker = oldHasScopeFix;
|
|
990
|
-
return this.factory.updateModuleDeclaration(input, modifiers, keyword, input.name, updatedBody);
|
|
1018
|
+
return this.factory.updateModuleDeclaration(input, modifiers, keyword, input.name, attributes, updatedBody);
|
|
991
1019
|
}
|
|
992
1020
|
if (body !== undefined) {
|
|
993
1021
|
// A nested `namespace a.b` is transformed now: it needs no visibility painting.
|
|
@@ -996,10 +1024,10 @@ export class DeclarationTransformer extends Transformer {
|
|
|
996
1024
|
const inner = this.lateStatementReplacements.get(original);
|
|
997
1025
|
this.lateStatementReplacements.delete(original);
|
|
998
1026
|
this.needsDeclare = saveNeedsDeclare;
|
|
999
|
-
return this.factory.updateModuleDeclaration(input, modifiers, keyword, input.name, inner);
|
|
1027
|
+
return this.factory.updateModuleDeclaration(input, modifiers, keyword, input.name, attributes, inner);
|
|
1000
1028
|
}
|
|
1001
1029
|
this.needsDeclare = saveNeedsDeclare;
|
|
1002
|
-
return this.factory.updateModuleDeclaration(input, modifiers, keyword, input.name, undefined);
|
|
1030
|
+
return this.factory.updateModuleDeclaration(input, modifiers, keyword, input.name, attributes, undefined);
|
|
1003
1031
|
}
|
|
1004
1032
|
stripExportModifiersOfList(list) {
|
|
1005
1033
|
const nodes = [];
|
|
@@ -1015,7 +1043,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1015
1043
|
stripExportModifiers(statement) {
|
|
1016
1044
|
const parseNode = this.context.parseNode(statement);
|
|
1017
1045
|
// `export import` stays: imports aren't implicitly exported. So does `export default`.
|
|
1018
|
-
if (statement.kind ===
|
|
1046
|
+
if (statement.kind === 273 /* SyntaxKind.ImportEqualsDeclaration */ ||
|
|
1019
1047
|
(parseNode !== undefined && this.resolver.getEffectiveDeclarationFlags(parseNode, 2048 /* ModifierFlags.Default */) !== 0) ||
|
|
1020
1048
|
!canHaveModifiers(statement))
|
|
1021
1049
|
return statement;
|
|
@@ -1042,7 +1070,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1042
1070
|
if (node instanceof EnumDeclaration)
|
|
1043
1071
|
return factory.updateEnumDeclaration(node, modifiers, node.name, node.members);
|
|
1044
1072
|
if (node instanceof ModuleDeclaration)
|
|
1045
|
-
return factory.updateModuleDeclaration(node, modifiers, node.keyword, node.name, node.body);
|
|
1073
|
+
return factory.updateModuleDeclaration(node, modifiers, node.keyword, node.name, node.attributes, node.body);
|
|
1046
1074
|
if (node instanceof ImportDeclaration)
|
|
1047
1075
|
return factory.updateImportDeclaration(node, modifiers, node.importClause, node.moduleSpecifier, node.attributes);
|
|
1048
1076
|
if (node instanceof ExportDeclaration)
|
|
@@ -1219,8 +1247,8 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1219
1247
|
if (this.tracker.isolatedDeclarations &&
|
|
1220
1248
|
member.initializer !== undefined &&
|
|
1221
1249
|
value.hasExternalReferences &&
|
|
1222
|
-
member.name.kind !==
|
|
1223
|
-
this.tracker.addDiagnostic(createDiagnosticForNode(member,
|
|
1250
|
+
member.name.kind !== 169 /* SyntaxKind.ComputedPropertyName */)
|
|
1251
|
+
this.tracker.addDiagnostic(createDiagnosticForNode(member, 1805 /* Diagnostics.Enum_member_initializers_must_be_computable_without_references_to_external_symbols_with_isolatedDeclarations */, []));
|
|
1224
1252
|
let initializer = undefined;
|
|
1225
1253
|
if (value.kind === 1 /* ConstantKind.Number */)
|
|
1226
1254
|
initializer = this.createNumber(value.number);
|
|
@@ -1253,7 +1281,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1253
1281
|
const name = input.name;
|
|
1254
1282
|
if (name instanceof Identifier)
|
|
1255
1283
|
return this.factory.created(new ImportEqualsDeclaration(undefined, false, name, this.factory.created(new ExternalModuleReference(specifier))));
|
|
1256
|
-
if (!(name instanceof BindingPattern) || name.kind ===
|
|
1284
|
+
if (!(name instanceof BindingPattern) || name.kind === 209 /* SyntaxKind.ArrayBindingPattern */)
|
|
1257
1285
|
return undefined;
|
|
1258
1286
|
const specifiers = [];
|
|
1259
1287
|
for (const element of name.elements.nodes) {
|
|
@@ -1263,7 +1291,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1263
1291
|
specifiers.push(this.factory.created(new ImportSpecifier(false, element.propertyName, element.name)));
|
|
1264
1292
|
}
|
|
1265
1293
|
const clause = this.factory.created(new ImportClause(undefined, undefined, this.factory.created(new NamedImports(this.factory.createNodeList(specifiers)))));
|
|
1266
|
-
return this.factory.created(new ImportDeclaration(
|
|
1294
|
+
return this.factory.created(new ImportDeclaration(274 /* SyntaxKind.ImportDeclaration */, undefined, clause, specifier, undefined));
|
|
1267
1295
|
}
|
|
1268
1296
|
/** Finds `module.exports =` assignments anywhere in the file. */
|
|
1269
1297
|
visitModuleExportsAssignment(node) {
|
|
@@ -1354,9 +1382,9 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1354
1382
|
const statement = input.parent;
|
|
1355
1383
|
if (isCommonJSAliasExport(input) &&
|
|
1356
1384
|
statement !== undefined &&
|
|
1357
|
-
statement.kind ===
|
|
1385
|
+
statement.kind === 246 /* SyntaxKind.ExpressionStatement */ &&
|
|
1358
1386
|
statement.parent !== undefined &&
|
|
1359
|
-
statement.parent.kind ===
|
|
1387
|
+
statement.parent.kind === 308 /* SyntaxKind.SourceFile */)
|
|
1360
1388
|
return this.transformBinaryExpressionToExportDeclaration(input, name);
|
|
1361
1389
|
if (input instanceof BinaryExpression) {
|
|
1362
1390
|
const right = skipParenthesesOnly(input.right);
|
|
@@ -1419,7 +1447,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1419
1447
|
tracker.classSymbolTracked = false;
|
|
1420
1448
|
if (needsIsolation) {
|
|
1421
1449
|
const namespaceName = factory.createUniqueName('_ns', 16 /* GeneratedIdentifierFlags.Optimistic */);
|
|
1422
|
-
const namespace = factory.created(new ModuleDeclaration(this.declareModifiers(), 145 /* SyntaxKind.NamespaceKeyword */, namespaceName, factory.created(new ModuleBlock(factory.createNodeList([classDeclaration])))));
|
|
1450
|
+
const namespace = factory.created(new ModuleDeclaration(this.declareModifiers(), 145 /* SyntaxKind.NamespaceKeyword */, namespaceName, undefined, factory.created(new ModuleBlock(factory.createNodeList([classDeclaration])))));
|
|
1423
1451
|
const aliasBase = name instanceof Identifier && isIdentifierText('_' + name.text) ? '_' + name.text : '_exported';
|
|
1424
1452
|
const alias = factory.createUniqueName(aliasBase, 16 /* GeneratedIdentifierFlags.Optimistic */);
|
|
1425
1453
|
const importEquals = factory.created(new ImportEqualsDeclaration(undefined, false, alias, factory.created(new QualifiedName(namespaceName, className))));
|
|
@@ -1469,7 +1497,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1469
1497
|
const stripped = [];
|
|
1470
1498
|
for (const member of members)
|
|
1471
1499
|
stripped.push(this.stripDeclareModifier(member));
|
|
1472
|
-
return this.factory.created(new ModuleDeclaration(this.declareModifiers(), 145 /* SyntaxKind.NamespaceKeyword */, name, this.factory.created(new ModuleBlock(this.factory.createNodeList(stripped)))));
|
|
1500
|
+
return this.factory.created(new ModuleDeclaration(this.declareModifiers(), 145 /* SyntaxKind.NamespaceKeyword */, name, undefined, this.factory.created(new ModuleBlock(this.factory.createNodeList(stripped)))));
|
|
1473
1501
|
}
|
|
1474
1502
|
stripDeclareModifier(node) {
|
|
1475
1503
|
const modifiers = getModifiers(node);
|
|
@@ -1508,8 +1536,17 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1508
1536
|
const property = this.tryGetPropertyName(left);
|
|
1509
1537
|
if (property === '' || !isIdentifierText(property))
|
|
1510
1538
|
return false;
|
|
1511
|
-
|
|
1539
|
+
const hostId = this.getExpandoHostId(declaration);
|
|
1540
|
+
if (isDeclaration(declaration) && this.isDeclarationAndNotVisible(declaration)) {
|
|
1541
|
+
// Writing the type of a visible declaration, such as `typeof f`, can make the host visible later.
|
|
1542
|
+
let deferred = this.deferredExpandoAssignments.get(hostId);
|
|
1543
|
+
if (deferred === undefined) {
|
|
1544
|
+
deferred = [];
|
|
1545
|
+
this.deferredExpandoAssignments.set(hostId, deferred);
|
|
1546
|
+
}
|
|
1547
|
+
deferred.push(node);
|
|
1512
1548
|
return false;
|
|
1549
|
+
}
|
|
1513
1550
|
if (declaration instanceof FunctionDeclaration && !shouldEmitFunctionProperties(declaration))
|
|
1514
1551
|
return false;
|
|
1515
1552
|
this.transformExpandoHost(name, declaration);
|
|
@@ -1522,23 +1559,24 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1522
1559
|
localName = exportName;
|
|
1523
1560
|
if (localName === undefined || isNonContextualKeyword(stringToToken(localName.text)))
|
|
1524
1561
|
localName = this.factory.createGeneratedNameForNode(node, 0 /* GeneratedIdentifierFlags.None */, '', '');
|
|
1525
|
-
const hostId = this.getExpandoHostId(declaration);
|
|
1526
1562
|
const scope = this.enterDiagnosticContext(node);
|
|
1527
1563
|
let members = this.expandoMembers.get(hostId);
|
|
1528
1564
|
if (members === undefined) {
|
|
1529
1565
|
members = [];
|
|
1530
1566
|
this.expandoMembers.set(hostId, members);
|
|
1531
1567
|
}
|
|
1568
|
+
let hasExport = false;
|
|
1569
|
+
for (const member of members)
|
|
1570
|
+
if (member.kind === 280 /* SyntaxKind.ExportDeclaration */)
|
|
1571
|
+
hasExport = true;
|
|
1532
1572
|
if (node.right instanceof Identifier) {
|
|
1533
|
-
// Alias-like: `export { name }` or `export { name as alias }
|
|
1573
|
+
// Alias-like: `export { name }` or `export { name as alias }`; the other members stay exported.
|
|
1574
|
+
if (!hasExport)
|
|
1575
|
+
this.addExportModifierToExpandoMembers(members);
|
|
1534
1576
|
members.push(this.transformBinaryExpressionToExportDeclaration(node, exportName));
|
|
1535
1577
|
this.exitDiagnosticContext(scope);
|
|
1536
1578
|
return true;
|
|
1537
1579
|
}
|
|
1538
|
-
let hasExport = false;
|
|
1539
|
-
for (const member of members)
|
|
1540
|
-
if (member.kind === 279 /* SyntaxKind.ExportDeclaration */)
|
|
1541
|
-
hasExport = true;
|
|
1542
1580
|
const variable = this.factory.createVariableStatement(hasExport ? this.factory.createModifierList([this.factory.createToken(94 /* SyntaxKind.ExportKeyword */)]) : undefined, this.factory.createVariableDeclarationList(this.factory.createNodeList([
|
|
1543
1581
|
this.factory.createVariableDeclaration(localName, undefined, this.ensureType(node, false), undefined),
|
|
1544
1582
|
]), 0 /* NodeFlags.None */));
|
|
@@ -1548,13 +1586,17 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1548
1586
|
statements.push(this.createExportDeclaration(local, exportName));
|
|
1549
1587
|
// Members stay exported after an `export {}` is added.
|
|
1550
1588
|
if (statements.length > 1 && !hasExport)
|
|
1551
|
-
|
|
1552
|
-
members[i] = this.replaceModifiers(members[i], this.createModifiers(32 /* ModifierFlags.Export */ | getCombinedModifierFlags(members[i])));
|
|
1589
|
+
this.addExportModifierToExpandoMembers(members);
|
|
1553
1590
|
for (const statement of statements)
|
|
1554
1591
|
members.push(statement);
|
|
1555
1592
|
this.exitDiagnosticContext(scope);
|
|
1556
1593
|
return true;
|
|
1557
1594
|
}
|
|
1595
|
+
/** Adds `export` to a host's members, before the first `export {}` is added to them. */
|
|
1596
|
+
addExportModifierToExpandoMembers(members) {
|
|
1597
|
+
for (let i = 0; i < members.length; i++)
|
|
1598
|
+
members[i] = this.replaceModifiers(members[i], this.createModifiers(32 /* ModifierFlags.Export */ | getCombinedModifierFlags(members[i])));
|
|
1599
|
+
}
|
|
1558
1600
|
tryGetPropertyName(node) {
|
|
1559
1601
|
if (node instanceof ElementAccessExpression)
|
|
1560
1602
|
return this.resolver.getElementAccessExpressionName(node);
|
|
@@ -1597,7 +1639,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1597
1639
|
}
|
|
1598
1640
|
this.tracker.reportExpandoFunctionErrors(declaration);
|
|
1599
1641
|
if (defaultExport) {
|
|
1600
|
-
if (declaration.parent !== undefined && declaration.parent.kind ===
|
|
1642
|
+
if (declaration.parent !== undefined && declaration.parent.kind === 308 /* SyntaxKind.SourceFile */)
|
|
1601
1643
|
this.resultHasExternalModuleIndicator = true;
|
|
1602
1644
|
this.resultHasScopeMarker = true;
|
|
1603
1645
|
replacement.push(this.factory.created(new ExportAssignment(undefined, false, undefined, name)));
|
|
@@ -1610,6 +1652,13 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1610
1652
|
}
|
|
1611
1653
|
/** A function with its assigned properties as a namespace of the same name. */
|
|
1612
1654
|
createFullExpandoBlock(id) {
|
|
1655
|
+
// Assignments deferred while the host wasn't visible; they are deferred again if it still isn't.
|
|
1656
|
+
const deferred = this.deferredExpandoAssignments.get(id);
|
|
1657
|
+
if (deferred !== undefined) {
|
|
1658
|
+
this.deferredExpandoAssignments.delete(id);
|
|
1659
|
+
for (const assignment of deferred)
|
|
1660
|
+
this.transformExpandoAssignment(assignment);
|
|
1661
|
+
}
|
|
1613
1662
|
const host = this.expandoHosts.get(id);
|
|
1614
1663
|
const addOns = this.expandoMembers.get(id);
|
|
1615
1664
|
if (addOns === undefined || host === undefined)
|
|
@@ -1630,7 +1679,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1630
1679
|
if (name === undefined)
|
|
1631
1680
|
return host;
|
|
1632
1681
|
const result = statements.slice();
|
|
1633
|
-
result.push(this.factory.created(new ModuleDeclaration(modifiers, 145 /* SyntaxKind.NamespaceKeyword */, name, this.factory.created(new ModuleBlock(this.factory.createNodeList(addOns))))));
|
|
1682
|
+
result.push(this.factory.created(new ModuleDeclaration(modifiers, 145 /* SyntaxKind.NamespaceKeyword */, name, undefined, this.factory.created(new ModuleBlock(this.factory.createNodeList(addOns))))));
|
|
1634
1683
|
return this.factory.createSyntaxList(result);
|
|
1635
1684
|
}
|
|
1636
1685
|
/** The `this.x = …` members of a JavaScript class, as property declarations. */
|
|
@@ -1659,7 +1708,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1659
1708
|
if (container.parent !== classNode)
|
|
1660
1709
|
return false;
|
|
1661
1710
|
const isStaticMember = hasSyntacticModifier(container, 256 /* ModifierFlags.Static */) ||
|
|
1662
|
-
container.kind ===
|
|
1711
|
+
container.kind === 177 /* SyntaxKind.ClassStaticBlockDeclaration */;
|
|
1663
1712
|
const assignment = node;
|
|
1664
1713
|
let name = getElementOrPropertyAccessName(assignment.left);
|
|
1665
1714
|
if (name === undefined)
|
|
@@ -1669,7 +1718,7 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1669
1718
|
return false;
|
|
1670
1719
|
this.seenProperties.add(key);
|
|
1671
1720
|
const heritage = getHeritageClauses(classNode);
|
|
1672
|
-
if (heritage !== undefined && heritage.nodes.length > 0 && !isClassExtendingNull(
|
|
1721
|
+
if (heritage !== undefined && heritage.nodes.length > 0 && !isClassExtendingNull(classNode)) {
|
|
1673
1722
|
// A base class may provide the member; that needs types.
|
|
1674
1723
|
this.tracker.reportInferenceFallback(classNode);
|
|
1675
1724
|
if (this.resolver.isThisPropertyAssignmentDeclarationRedundant(node))
|
|
@@ -1681,10 +1730,12 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1681
1730
|
return false;
|
|
1682
1731
|
if (name instanceof Identifier && !isIdentifierText(name.text))
|
|
1683
1732
|
name = this.factory.createStringLiteralFromNode(name);
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1733
|
+
// JSDoc modifiers such as `@readonly` and `@private` apply to the property.
|
|
1734
|
+
let modifierFlags = this.ensureModifierFlags(node);
|
|
1735
|
+
if (isStaticMember)
|
|
1736
|
+
modifierFlags |= 256 /* ModifierFlags.Static */;
|
|
1737
|
+
const property = this.factory.created(new PropertyDeclaration(this.createModifiers(modifierFlags), name, undefined, this.ensureType(node, false), undefined));
|
|
1738
|
+
if (node.parent !== undefined && node.parent.kind === 246 /* SyntaxKind.ExpressionStatement */)
|
|
1688
1739
|
this.context.assignCommentRange(property, node.parent);
|
|
1689
1740
|
this.thisPropertyAssignments.push(property);
|
|
1690
1741
|
return true;
|
|
@@ -1725,8 +1776,8 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1725
1776
|
ensureModifierFlags(node) {
|
|
1726
1777
|
// No `async` or `override` in declaration files, and `public` is implied.
|
|
1727
1778
|
let mask = 131071 /* ModifierFlags.All */ ^ (1 /* ModifierFlags.Public */ | 1024 /* ModifierFlags.Async */ | 16 /* ModifierFlags.Override */);
|
|
1728
|
-
let additions = this.needsDeclare && node.kind !==
|
|
1729
|
-
if (node.parent === undefined || node.parent.kind !==
|
|
1779
|
+
let additions = this.needsDeclare && node.kind !== 266 /* SyntaxKind.InterfaceDeclaration */ ? 128 /* ModifierFlags.Ambient */ : 0 /* ModifierFlags.None */;
|
|
1780
|
+
if (node.parent === undefined || node.parent.kind !== 308 /* SyntaxKind.SourceFile */) {
|
|
1730
1781
|
mask ^= 128 /* ModifierFlags.Ambient */;
|
|
1731
1782
|
additions = 0 /* ModifierFlags.None */;
|
|
1732
1783
|
}
|
|
@@ -1809,10 +1860,10 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1809
1860
|
if (this.shouldPrintWithInitializer(node))
|
|
1810
1861
|
return undefined;
|
|
1811
1862
|
const type = getType(node);
|
|
1812
|
-
if (node.kind !==
|
|
1813
|
-
node.kind !==
|
|
1863
|
+
if (node.kind !== 279 /* SyntaxKind.ExportAssignment */ &&
|
|
1864
|
+
node.kind !== 210 /* SyntaxKind.BindingElement */ &&
|
|
1814
1865
|
type !== undefined &&
|
|
1815
|
-
(node.kind !==
|
|
1866
|
+
(node.kind !== 171 /* SyntaxKind.Parameter */ ||
|
|
1816
1867
|
!this.resolver.requiresAddingImplicitUndefined(node, this.enclosingDeclaration))) {
|
|
1817
1868
|
const file = this.tracker.currentSourceFile;
|
|
1818
1869
|
if (file === undefined || !file.isJS())
|
|
@@ -1850,11 +1901,11 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1850
1901
|
}
|
|
1851
1902
|
canHaveLiteralInitializer(node) {
|
|
1852
1903
|
switch (node.kind) {
|
|
1853
|
-
case
|
|
1854
|
-
case
|
|
1904
|
+
case 174 /* SyntaxKind.PropertyDeclaration */:
|
|
1905
|
+
case 173 /* SyntaxKind.PropertySignature */:
|
|
1855
1906
|
return !this.isPrivate(node);
|
|
1856
|
-
case
|
|
1857
|
-
case
|
|
1907
|
+
case 171 /* SyntaxKind.Parameter */:
|
|
1908
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
1858
1909
|
return true;
|
|
1859
1910
|
}
|
|
1860
1911
|
return false;
|
|
@@ -1913,13 +1964,13 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1913
1964
|
// A module augmentation of an export may depend on the import.
|
|
1914
1965
|
if (this.resolver.isImportRequiredByAugmentation(declaration)) {
|
|
1915
1966
|
if (this.tracker.isolatedDeclarations)
|
|
1916
|
-
this.tracker.addDiagnostic(createDiagnosticForNode(declaration,
|
|
1967
|
+
this.tracker.addDiagnostic(createDiagnosticForNode(declaration, 1810 /* Diagnostics.Declaration_emit_for_this_file_requires_preserving_this_import_for_augmentations_This_is_not_supported_with_isolatedDeclarations */, []));
|
|
1917
1968
|
return this.updateImport(declaration, undefined);
|
|
1918
1969
|
}
|
|
1919
1970
|
return undefined;
|
|
1920
1971
|
}
|
|
1921
1972
|
updateImport(declaration, clause) {
|
|
1922
|
-
return this.factory.updateImportDeclaration(declaration, declaration.modifiers, clause, this.rewriteModuleSpecifier(declaration, declaration.moduleSpecifier),
|
|
1973
|
+
return this.factory.updateImportDeclaration(declaration, declaration.modifiers, clause, this.rewriteModuleSpecifier(declaration, declaration.moduleSpecifier), declaration.attributes);
|
|
1923
1974
|
}
|
|
1924
1975
|
// Visibility helpers
|
|
1925
1976
|
parseNode(node) {
|
|
@@ -1931,24 +1982,24 @@ export class DeclarationTransformer extends Transformer {
|
|
|
1931
1982
|
isDeclarationAndNotVisible(node) {
|
|
1932
1983
|
const parseNode = this.parseNode(node);
|
|
1933
1984
|
switch (parseNode.kind) {
|
|
1934
|
-
case
|
|
1935
|
-
case
|
|
1936
|
-
case
|
|
1937
|
-
case
|
|
1938
|
-
case
|
|
1939
|
-
case
|
|
1940
|
-
case
|
|
1985
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
1986
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
1987
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
1988
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
1989
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
1990
|
+
case 346 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
1991
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
1941
1992
|
return !this.resolver.isDeclarationVisible(parseNode);
|
|
1942
1993
|
// These filter their members' visibility themselves.
|
|
1943
|
-
case
|
|
1994
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
1944
1995
|
return !this.getBindingNameVisible(parseNode);
|
|
1945
|
-
case
|
|
1996
|
+
case 177 /* SyntaxKind.ClassStaticBlockDeclaration */:
|
|
1946
1997
|
return true;
|
|
1947
1998
|
}
|
|
1948
1999
|
return false;
|
|
1949
2000
|
}
|
|
1950
2001
|
getBindingNameVisible(element) {
|
|
1951
|
-
if (element.kind ===
|
|
2002
|
+
if (element.kind === 234 /* SyntaxKind.OmittedExpression */)
|
|
1952
2003
|
return false;
|
|
1953
2004
|
const name = getName(element);
|
|
1954
2005
|
if (name === undefined)
|
|
@@ -2036,12 +2087,12 @@ function preservedReferences(references) {
|
|
|
2036
2087
|
}
|
|
2037
2088
|
/** Whether a node is a declaration (type parameters only when attached). */
|
|
2038
2089
|
function isDeclaration(node) {
|
|
2039
|
-
if (node.kind ===
|
|
2090
|
+
if (node.kind === 170 /* SyntaxKind.TypeParameter */)
|
|
2040
2091
|
return node.parent !== undefined;
|
|
2041
2092
|
return isDeclarationNode(node);
|
|
2042
2093
|
}
|
|
2043
2094
|
function isEntityName(node) {
|
|
2044
|
-
return node.kind === 79 /* SyntaxKind.Identifier */ || node.kind ===
|
|
2095
|
+
return node.kind === 79 /* SyntaxKind.Identifier */ || node.kind === 168 /* SyntaxKind.QualifiedName */;
|
|
2045
2096
|
}
|
|
2046
2097
|
function isThisParameterNode(node) {
|
|
2047
2098
|
return node instanceof ParameterDeclaration && node.name instanceof Identifier && node.name.text === 'this';
|
|
@@ -2049,51 +2100,51 @@ function isThisParameterNode(node) {
|
|
|
2049
2100
|
/** Declarations whose scope names in their types are resolved from. */
|
|
2050
2101
|
function isEnclosingDeclaration(node) {
|
|
2051
2102
|
switch (node.kind) {
|
|
2052
|
-
case
|
|
2053
|
-
case
|
|
2054
|
-
case
|
|
2055
|
-
case
|
|
2056
|
-
case
|
|
2057
|
-
case
|
|
2058
|
-
case
|
|
2059
|
-
case
|
|
2060
|
-
case
|
|
2103
|
+
case 308 /* SyntaxKind.SourceFile */:
|
|
2104
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
2105
|
+
case 346 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
2106
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
2107
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
2108
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
2109
|
+
case 183 /* SyntaxKind.IndexSignature */:
|
|
2110
|
+
case 202 /* SyntaxKind.MappedType */:
|
|
2111
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
2061
2112
|
return true;
|
|
2062
2113
|
}
|
|
2063
2114
|
return isFunctionLike(node);
|
|
2064
2115
|
}
|
|
2065
2116
|
function isLateVisibilityPaintedStatement(node) {
|
|
2066
2117
|
switch (node.kind) {
|
|
2067
|
-
case
|
|
2068
|
-
case
|
|
2069
|
-
case
|
|
2070
|
-
case
|
|
2071
|
-
case
|
|
2072
|
-
case
|
|
2073
|
-
case
|
|
2074
|
-
case
|
|
2075
|
-
case
|
|
2076
|
-
case
|
|
2077
|
-
case
|
|
2118
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
2119
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
2120
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
2121
|
+
case 245 /* SyntaxKind.VariableStatement */:
|
|
2122
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
2123
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
2124
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
2125
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
2126
|
+
case 346 /* SyntaxKind.JSTypeAliasDeclaration */:
|
|
2127
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
2128
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
2078
2129
|
return true;
|
|
2079
2130
|
}
|
|
2080
2131
|
return false;
|
|
2081
2132
|
}
|
|
2082
2133
|
function isExternalModuleIndicator(node) {
|
|
2083
2134
|
return (isAnyImportOrReExport(node) ||
|
|
2084
|
-
node.kind ===
|
|
2135
|
+
node.kind === 279 /* SyntaxKind.ExportAssignment */ ||
|
|
2085
2136
|
hasSyntacticModifier(node, 32 /* ModifierFlags.Export */));
|
|
2086
2137
|
}
|
|
2087
2138
|
/** Whether a statement in a namespace without `export {}` would stop being exported implicitly. */
|
|
2088
2139
|
function needsScopeMarker(node) {
|
|
2089
2140
|
return (!isAnyImportOrReExport(node) &&
|
|
2090
|
-
node.kind !==
|
|
2141
|
+
node.kind !== 279 /* SyntaxKind.ExportAssignment */ &&
|
|
2091
2142
|
!hasSyntacticModifier(node, 32 /* ModifierFlags.Export */) &&
|
|
2092
2143
|
!isAmbientModule(node));
|
|
2093
2144
|
}
|
|
2094
2145
|
function hasScopeMarker(statements) {
|
|
2095
2146
|
for (const statement of statements.nodes)
|
|
2096
|
-
if (statement.kind ===
|
|
2147
|
+
if (statement.kind === 279 /* SyntaxKind.ExportAssignment */ || statement.kind === 280 /* SyntaxKind.ExportDeclaration */)
|
|
2097
2148
|
return true;
|
|
2098
2149
|
return false;
|
|
2099
2150
|
}
|
|
@@ -2108,28 +2159,28 @@ function maskModifierFlags(node, mask, additions) {
|
|
|
2108
2159
|
}
|
|
2109
2160
|
function isImplicitlyExportedJSDocDeclaration(node) {
|
|
2110
2161
|
const parent = node.parent;
|
|
2111
|
-
if (parent === undefined || parent.kind !==
|
|
2162
|
+
if (parent === undefined || parent.kind !== 308 /* SyntaxKind.SourceFile */)
|
|
2112
2163
|
return false;
|
|
2113
2164
|
if (!isExternalOrCommonJSModule(parent))
|
|
2114
2165
|
return false;
|
|
2115
|
-
if (node.kind ===
|
|
2166
|
+
if (node.kind === 346 /* SyntaxKind.JSTypeAliasDeclaration */)
|
|
2116
2167
|
return true;
|
|
2117
|
-
return node.kind ===
|
|
2168
|
+
return node.kind === 269 /* SyntaxKind.ModuleDeclaration */ && (node.flags & 8 /* NodeFlags.Reparsed */) !== 0;
|
|
2118
2169
|
}
|
|
2119
2170
|
function canHaveModifiers(node) {
|
|
2120
2171
|
switch (node.kind) {
|
|
2121
|
-
case
|
|
2122
|
-
case
|
|
2123
|
-
case
|
|
2124
|
-
case
|
|
2125
|
-
case
|
|
2126
|
-
case
|
|
2127
|
-
case
|
|
2128
|
-
case
|
|
2129
|
-
case
|
|
2130
|
-
case
|
|
2131
|
-
case
|
|
2132
|
-
case
|
|
2172
|
+
case 245 /* SyntaxKind.VariableStatement */:
|
|
2173
|
+
case 264 /* SyntaxKind.FunctionDeclaration */:
|
|
2174
|
+
case 265 /* SyntaxKind.ClassDeclaration */:
|
|
2175
|
+
case 266 /* SyntaxKind.InterfaceDeclaration */:
|
|
2176
|
+
case 267 /* SyntaxKind.TypeAliasDeclaration */:
|
|
2177
|
+
case 268 /* SyntaxKind.EnumDeclaration */:
|
|
2178
|
+
case 269 /* SyntaxKind.ModuleDeclaration */:
|
|
2179
|
+
case 273 /* SyntaxKind.ImportEqualsDeclaration */:
|
|
2180
|
+
case 274 /* SyntaxKind.ImportDeclaration */:
|
|
2181
|
+
case 347 /* SyntaxKind.JSImportDeclaration */:
|
|
2182
|
+
case 279 /* SyntaxKind.ExportAssignment */:
|
|
2183
|
+
case 280 /* SyntaxKind.ExportDeclaration */:
|
|
2133
2184
|
return true;
|
|
2134
2185
|
}
|
|
2135
2186
|
return false;
|
|
@@ -2137,20 +2188,20 @@ function canHaveModifiers(node) {
|
|
|
2137
2188
|
/** Kinds whose type the resolver writes from the declaration rather than a signature. */
|
|
2138
2189
|
function hasInferredType(node) {
|
|
2139
2190
|
switch (node.kind) {
|
|
2140
|
-
case
|
|
2141
|
-
case
|
|
2142
|
-
case
|
|
2143
|
-
case
|
|
2144
|
-
case
|
|
2145
|
-
case
|
|
2146
|
-
case
|
|
2147
|
-
case
|
|
2148
|
-
case
|
|
2149
|
-
case
|
|
2150
|
-
case
|
|
2151
|
-
case
|
|
2152
|
-
case
|
|
2153
|
-
case
|
|
2191
|
+
case 171 /* SyntaxKind.Parameter */:
|
|
2192
|
+
case 173 /* SyntaxKind.PropertySignature */:
|
|
2193
|
+
case 174 /* SyntaxKind.PropertyDeclaration */:
|
|
2194
|
+
case 210 /* SyntaxKind.BindingElement */:
|
|
2195
|
+
case 213 /* SyntaxKind.PropertyAccessExpression */:
|
|
2196
|
+
case 214 /* SyntaxKind.ElementAccessExpression */:
|
|
2197
|
+
case 228 /* SyntaxKind.BinaryExpression */:
|
|
2198
|
+
case 215 /* SyntaxKind.CallExpression */:
|
|
2199
|
+
case 262 /* SyntaxKind.VariableDeclaration */:
|
|
2200
|
+
case 279 /* SyntaxKind.ExportAssignment */:
|
|
2201
|
+
case 304 /* SyntaxKind.PropertyAssignment */:
|
|
2202
|
+
case 305 /* SyntaxKind.ShorthandPropertyAssignment */:
|
|
2203
|
+
case 334 /* SyntaxKind.JSDocParameterTag */:
|
|
2204
|
+
case 341 /* SyntaxKind.JSDocPropertyTag */:
|
|
2154
2205
|
return true;
|
|
2155
2206
|
}
|
|
2156
2207
|
return false;
|
|
@@ -2166,7 +2217,7 @@ function isPrimitiveLiteralValue(node, includeBigInt) {
|
|
|
2166
2217
|
return true;
|
|
2167
2218
|
case 9 /* SyntaxKind.BigIntLiteral */:
|
|
2168
2219
|
return includeBigInt;
|
|
2169
|
-
case
|
|
2220
|
+
case 226 /* SyntaxKind.PrefixUnaryExpression */: {
|
|
2170
2221
|
const unary = node;
|
|
2171
2222
|
const operand = unary.operand;
|
|
2172
2223
|
if (unary.operator === 40 /* SyntaxKind.MinusToken */)
|
|
@@ -2180,7 +2231,7 @@ function isPrimitiveLiteralValue(node, includeBigInt) {
|
|
|
2180
2231
|
}
|
|
2181
2232
|
function skipParenthesesOnly(node) {
|
|
2182
2233
|
let current = node;
|
|
2183
|
-
while (current.kind ===
|
|
2234
|
+
while (current.kind === 219 /* SyntaxKind.ParenthesizedExpression */)
|
|
2184
2235
|
current = getExpression(current);
|
|
2185
2236
|
return current;
|
|
2186
2237
|
}
|
|
@@ -2188,7 +2239,7 @@ function skipParenthesesOnly(node) {
|
|
|
2188
2239
|
function skipOuterExpressions(node) {
|
|
2189
2240
|
let current = node;
|
|
2190
2241
|
for (;;) {
|
|
2191
|
-
if (current.kind ===
|
|
2242
|
+
if (current.kind === 219 /* SyntaxKind.ParenthesizedExpression */)
|
|
2192
2243
|
current = getExpression(current);
|
|
2193
2244
|
else if (current instanceof BinaryExpression &&
|
|
2194
2245
|
(current.operatorToken.kind === 63 /* SyntaxKind.EqualsToken */ || current.operatorToken.kind === 27 /* SyntaxKind.CommaToken */))
|
|
@@ -2240,11 +2291,11 @@ function asteriskOf(fn) {
|
|
|
2240
2291
|
}
|
|
2241
2292
|
/** `const f = function () {}` or `const f = () => {}`. */
|
|
2242
2293
|
function isFunctionValuedVariable(node) {
|
|
2243
|
-
if (node.kind !==
|
|
2294
|
+
if (node.kind !== 262 /* SyntaxKind.VariableDeclaration */)
|
|
2244
2295
|
return false;
|
|
2245
2296
|
const initializer = getInitializer(node);
|
|
2246
2297
|
return (initializer !== undefined &&
|
|
2247
|
-
(initializer.kind ===
|
|
2298
|
+
(initializer.kind === 220 /* SyntaxKind.FunctionExpression */ || initializer.kind === 221 /* SyntaxKind.ArrowFunction */));
|
|
2248
2299
|
}
|
|
2249
2300
|
function appendFlattened(result, node) {
|
|
2250
2301
|
if (node instanceof SyntaxList)
|
|
@@ -2280,7 +2331,7 @@ function isCommonJSAliasExport(node) {
|
|
|
2280
2331
|
}
|
|
2281
2332
|
function getLeftmostAccessExpression(node) {
|
|
2282
2333
|
let current = node;
|
|
2283
|
-
while (current.kind ===
|
|
2334
|
+
while (current.kind === 213 /* SyntaxKind.PropertyAccessExpression */ || current.kind === 214 /* SyntaxKind.ElementAccessExpression */)
|
|
2284
2335
|
current = getExpression(current);
|
|
2285
2336
|
return current;
|
|
2286
2337
|
}
|
|
@@ -2298,15 +2349,20 @@ function shouldEmitFunctionProperties(fn) {
|
|
|
2298
2349
|
}
|
|
2299
2350
|
function isNonContextualKeyword(kind) {
|
|
2300
2351
|
return (kind >= 82 /* SyntaxKind.FirstKeyword */ &&
|
|
2301
|
-
kind <=
|
|
2302
|
-
!(kind >= 127 /* SyntaxKind.FirstContextualKeyword */ && kind <=
|
|
2352
|
+
kind <= 167 /* SyntaxKind.LastKeyword */ &&
|
|
2353
|
+
!(kind >= 127 /* SyntaxKind.FirstContextualKeyword */ && kind <= 167 /* SyntaxKind.LastContextualKeyword */));
|
|
2303
2354
|
}
|
|
2304
|
-
|
|
2305
|
-
|
|
2355
|
+
/** Whether a class's `extends` clause names exactly `null`. */
|
|
2356
|
+
function isClassExtendingNull(node) {
|
|
2357
|
+
const heritage = getHeritageClauses(node);
|
|
2358
|
+
if (heritage === undefined)
|
|
2306
2359
|
return false;
|
|
2307
|
-
for (const
|
|
2308
|
-
if (
|
|
2309
|
-
|
|
2360
|
+
for (const clause of heritage.nodes) {
|
|
2361
|
+
if (clause.token !== 95 /* SyntaxKind.ExtendsKeyword */)
|
|
2362
|
+
continue;
|
|
2363
|
+
const types = clause.types.nodes;
|
|
2364
|
+
return types.length === 1 && getExpression(types[0])?.kind === 105 /* SyntaxKind.NullKeyword */;
|
|
2365
|
+
}
|
|
2310
2366
|
return false;
|
|
2311
2367
|
}
|
|
2312
2368
|
function getTextOfPropertyName(name) {
|
|
@@ -2323,7 +2379,7 @@ function getTextOfPropertyName(name) {
|
|
|
2323
2379
|
/** The key of a class member for deduplicating `this.x` members: name, staticness and privateness. */
|
|
2324
2380
|
function thisPropertyKey(name, node, isStaticMember) {
|
|
2325
2381
|
const prefix = (isStaticMember ? 's' : 'i') + (name instanceof PrivateIdentifier ? '#' : '.');
|
|
2326
|
-
if (!(name instanceof ComputedPropertyName) && name.kind !==
|
|
2382
|
+
if (!(name instanceof ComputedPropertyName) && name.kind !== 214 /* SyntaxKind.ElementAccessExpression */) {
|
|
2327
2383
|
const text = getTextOfPropertyName(name);
|
|
2328
2384
|
if (text !== '' || name instanceof StringLiteral)
|
|
2329
2385
|
return prefix + text;
|
|
@@ -2341,7 +2397,7 @@ class ExpressionWalker extends NodeVisitor {
|
|
|
2341
2397
|
}
|
|
2342
2398
|
visitNode(node) {
|
|
2343
2399
|
// Only assignments and `Object.defineProperty` calls declare anything.
|
|
2344
|
-
if (node.kind ===
|
|
2400
|
+
if (node.kind === 228 /* SyntaxKind.BinaryExpression */ || node.kind === 215 /* SyntaxKind.CallExpression */) {
|
|
2345
2401
|
if (this.kind === 0 /* ExpressionWalkerKind.ModuleExports */)
|
|
2346
2402
|
this.transformer.visitModuleExportsAssignment(node);
|
|
2347
2403
|
else
|
|
@@ -2372,10 +2428,21 @@ function getTextOfJSDocComment(comment) {
|
|
|
2372
2428
|
for (const n of comment.nodes) {
|
|
2373
2429
|
if (n instanceof JSDocText)
|
|
2374
2430
|
text += n.text;
|
|
2375
|
-
else if (n.kind ===
|
|
2376
|
-
n.kind ===
|
|
2377
|
-
n.kind ===
|
|
2431
|
+
else if (n.kind === 320 /* SyntaxKind.JSDocLink */ ||
|
|
2432
|
+
n.kind === 321 /* SyntaxKind.JSDocLinkCode */ ||
|
|
2433
|
+
n.kind === 322 /* SyntaxKind.JSDocLinkPlain */)
|
|
2378
2434
|
text += getSourceTextOfNode(getSourceFileOfNode(n), n);
|
|
2379
2435
|
}
|
|
2380
2436
|
return text.trimEnd();
|
|
2381
2437
|
}
|
|
2438
|
+
function hasAnyBindingInitializers(pattern) {
|
|
2439
|
+
for (const element of pattern.elements.nodes) {
|
|
2440
|
+
if (!(element instanceof BindingElement))
|
|
2441
|
+
continue;
|
|
2442
|
+
if (element.initializer !== undefined)
|
|
2443
|
+
return true;
|
|
2444
|
+
if (element.name instanceof BindingPattern && hasAnyBindingInitializers(element.name))
|
|
2445
|
+
return true;
|
|
2446
|
+
}
|
|
2447
|
+
return false;
|
|
2448
|
+
}
|