Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deconflicting): add support for CallSignatures in deconflicting l…
…ogic
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...ration-bundler/transformers/deconflicter/visitor/deconflict-call-signature-declaration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {DeconflicterVisitorOptions} from "../deconflicter-visitor-options"; | ||
import {TS} from "../../../../../../type/ts"; | ||
import {cloneLexicalEnvironment} from "../../../util/clone-lexical-environment"; | ||
import {nodeArraysAreEqual} from "../../../util/node-arrays-are-equal"; | ||
import {ContinuationOptions} from "../deconflicter-options"; | ||
import {preserveMeta} from "../../../util/clone-node-with-meta"; | ||
|
||
/** | ||
* Deconflicts the given CallSignature. | ||
*/ | ||
export function deconflictCallSignatureDeclaration(options: DeconflicterVisitorOptions<TS.CallSignatureDeclaration>): TS.CallSignatureDeclaration | undefined { | ||
const {node, continuation, lexicalEnvironment, compatFactory} = options; | ||
|
||
// The type, type parameters, as well as the parameters share the same lexical environment | ||
const nextContinuationOptions: ContinuationOptions = {lexicalEnvironment: cloneLexicalEnvironment(lexicalEnvironment)}; | ||
|
||
const typeParametersContResult = | ||
node.typeParameters == null ? undefined : compatFactory.createNodeArray(node.typeParameters.map(typeParameter => continuation(typeParameter, nextContinuationOptions))); | ||
const parametersContResult = compatFactory.createNodeArray(node.parameters.map(parameter => continuation(parameter, nextContinuationOptions))); | ||
const typeContResult = node.type == null ? undefined : continuation(node.type, nextContinuationOptions); | ||
|
||
const isIdentical = | ||
nodeArraysAreEqual(typeParametersContResult, node.typeParameters) && | ||
nodeArraysAreEqual(parametersContResult, node.parameters) && | ||
typeContResult === node.type; | ||
|
||
if (isIdentical) { | ||
return node; | ||
} | ||
|
||
return preserveMeta( | ||
compatFactory.updateCallSignature(node, typeParametersContResult, parametersContResult, typeContResult), | ||
node, | ||
options | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters