Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
set(structure: Partial) {
callBaseSet(JsxElementBase.prototype, this, structure);
if (structure.attributes != null) {
const openingElement = this.getOpeningElement();
openingElement.getAttributes().forEach(a => a.remove());
openingElement.addAttributes(structure.attributes);
}
// todo: deprecate bodyText when implementing this
if (structure.children != null)
throw new errors.NotImplementedError("Setting JSX children is currently not implemented. Please open an issue if you need this.");
if (structure.bodyText != null)
this.setBodyText(structure.bodyText);
else if (structure.hasOwnProperty(nameof(structure.bodyText)))
this.setBodyTextInline("");
if (structure.name != null) {
this.getOpeningElement().getTagNameNode().replaceWithText(structure.name);
this.getClosingElement().getTagNameNode().replaceWithText(structure.name);
}
return this;
}
function getAsteriskInsertPos(node: Node) {
if (node.getKind() === SyntaxKind.FunctionDeclaration)
return node.getFirstChildByKindOrThrow(SyntaxKind.FunctionKeyword).getEnd();
const namedNode = node as any as NamedNode;
/* istanbul ignore if */
if (namedNode.getName == null)
throw new errors.NotImplementedError("Expected a name node for a non-function declaration.");
return namedNode.getNameNode().getStart();
}
function getAwaitInsertPos(node: Node) {
if (node.getKind() === SyntaxKind.ForOfStatement)
return node.getFirstChildByKindOrThrow(SyntaxKind.ForKeyword).getEnd();
throw new errors.NotImplementedError("Expected a for of statement node.");
}
function throwForNotModifierableNode(): never {
throw new errors.NotImplementedError(`Not implemented situation where node was not a ${nameof(ModifierableNode)}.`);
}
function getNodeToRename(thisNode: Node) {
if (TypeGuards.isIdentifier(thisNode))
return thisNode;
else if ((thisNode as any).getNameNode != null) {
const node = (thisNode as any).getNameNode() as Node;
errors.throwIfNullOrUndefined(node, "Expected to find a name node when renaming.");
if (TypeGuards.isArrayBindingPattern(node) || TypeGuards.isObjectBindingPattern(node))
throw new errors.NotImplementedError(`Not implemented renameable scenario for ${node.getKindName()}.`);
return node;
}
else {
throw new errors.NotImplementedError(`Not implemented renameable scenario for ${thisNode.getKindName()}`);
}
}
function getInsertPos(node: TypeParameteredNode & Node) {
const namedNode = node as any as (NamedNode & Node);
if (namedNode.getNameNode != null)
return namedNode.getNameNode().getEnd();
else if (TypeGuards.isCallSignatureDeclaration(node) || TypeGuards.isFunctionTypeNode(node))
return node.getFirstChildByKindOrThrow(SyntaxKind.OpenParenToken).getStart();
else
throw new errors.NotImplementedError(`Not implemented scenario inserting type parameters for node with kind ${node.getKindName()}.`);
}
getSignature() {
const signature = this._context.typeChecker.getSignatureFromNode(this);
if (signature == null)
throw new errors.NotImplementedError("Expected the node to have a signature.");
return signature;
}