* Note: if target is transient, then it is mutable, and mergeSymbol with both mutate and return it. * If target is not transient, mergeSymbol will produce a transient clone, mutate that and return it.
(target, source, unidirectional)
| 49138 | * If target is not transient, mergeSymbol will produce a transient clone, mutate that and return it. |
| 49139 | */ |
| 49140 | function mergeSymbol(target, source, unidirectional) { |
| 49141 | if (unidirectional === void 0) { unidirectional = false; } |
| 49142 | if (!(target.flags & getExcludedSymbolFlags(source.flags)) || |
| 49143 | (source.flags | target.flags) & 67108864 /* SymbolFlags.Assignment */) { |
| 49144 | if (source === target) { |
| 49145 | // This can happen when an export assigned namespace exports something also erroneously exported at the top level |
| 49146 | // See `declarationFileNoCrashOnExtraExportModifier` for an example |
| 49147 | return target; |
| 49148 | } |
| 49149 | if (!(target.flags & 33554432 /* SymbolFlags.Transient */)) { |
| 49150 | var resolvedTarget = resolveSymbol(target); |
| 49151 | if (resolvedTarget === unknownSymbol) { |
| 49152 | return source; |
| 49153 | } |
| 49154 | target = cloneSymbol(resolvedTarget); |
| 49155 | } |
| 49156 | // Javascript static-property-assignment declarations always merge, even though they are also values |
| 49157 | if (source.flags & 512 /* SymbolFlags.ValueModule */ && target.flags & 512 /* SymbolFlags.ValueModule */ && target.constEnumOnlyModule && !source.constEnumOnlyModule) { |
| 49158 | // reset flag when merging instantiated module into value module that has only const enums |
| 49159 | target.constEnumOnlyModule = false; |
| 49160 | } |
| 49161 | target.flags |= source.flags; |
| 49162 | if (source.valueDeclaration) { |
| 49163 | ts.setValueDeclaration(target, source.valueDeclaration); |
| 49164 | } |
| 49165 | ts.addRange(target.declarations, source.declarations); |
| 49166 | if (source.members) { |
| 49167 | if (!target.members) |
| 49168 | target.members = ts.createSymbolTable(); |
| 49169 | mergeSymbolTable(target.members, source.members, unidirectional); |
| 49170 | } |
| 49171 | if (source.exports) { |
| 49172 | if (!target.exports) |
| 49173 | target.exports = ts.createSymbolTable(); |
| 49174 | mergeSymbolTable(target.exports, source.exports, unidirectional); |
| 49175 | } |
| 49176 | if (!unidirectional) { |
| 49177 | recordMergedSymbol(target, source); |
| 49178 | } |
| 49179 | } |
| 49180 | else if (target.flags & 1024 /* SymbolFlags.NamespaceModule */) { |
| 49181 | // Do not report an error when merging `var globalThis` with the built-in `globalThis`, |
| 49182 | // as we will already report a "Declaration name conflicts..." error, and this error |
| 49183 | // won't make much sense. |
| 49184 | if (target !== globalThisSymbol) { |
| 49185 | error(source.declarations && ts.getNameOfDeclaration(source.declarations[0]), ts.Diagnostics.Cannot_augment_module_0_with_value_exports_because_it_resolves_to_a_non_module_entity, symbolToString(target)); |
| 49186 | } |
| 49187 | } |
| 49188 | else { // error |
| 49189 | var isEitherEnum = !!(target.flags & 384 /* SymbolFlags.Enum */ || source.flags & 384 /* SymbolFlags.Enum */); |
| 49190 | var isEitherBlockScoped_1 = !!(target.flags & 2 /* SymbolFlags.BlockScopedVariable */ || source.flags & 2 /* SymbolFlags.BlockScopedVariable */); |
| 49191 | var message = isEitherEnum ? ts.Diagnostics.Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations |
| 49192 | : isEitherBlockScoped_1 ? ts.Diagnostics.Cannot_redeclare_block_scoped_variable_0 |
| 49193 | : ts.Diagnostics.Duplicate_identifier_0; |
| 49194 | var sourceSymbolFile = source.declarations && ts.getSourceFileOfNode(source.declarations[0]); |
| 49195 | var targetSymbolFile = target.declarations && ts.getSourceFileOfNode(target.declarations[0]); |
| 49196 | var isSourcePlainJs = ts.isPlainJsFile(sourceSymbolFile, compilerOptions.checkJs); |
| 49197 | var isTargetPlainJs = ts.isPlainJsFile(targetSymbolFile, compilerOptions.checkJs); |
no test coverage detected