本文整理汇总了TypeScript中magic-string.slice函数的典型用法代码示例。如果您正苦于以下问题:TypeScript slice函数的具体用法?TypeScript slice怎么用?TypeScript slice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slice函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
nodesToRemove.forEach(node => {
// remove any trailing comma
const end = (output.slice(node.getEnd(), node.getEnd() + 1) === ',') ?
node.getEnd() + 1 :
node.getEnd();
output.remove(node.getFullStart(), end);
});
示例2:
decoratorsToRemove.forEach((nodesToRemove, containerNode) => {
if (ts.isArrayLiteralExpression(containerNode)) {
const items = containerNode.elements;
if (items.length === nodesToRemove.length) {
// remove any trailing semi-colon
const end = (output.slice(containerNode.getEnd(), containerNode.getEnd() + 1) === ';') ?
containerNode.getEnd() + 1 :
containerNode.getEnd();
output.remove(containerNode.parent !.getFullStart(), end);
} else {
nodesToRemove.forEach(node => {
// remove any trailing comma
const end = (output.slice(node.getEnd(), node.getEnd() + 1) === ',') ?
node.getEnd() + 1 :
node.getEnd();
output.remove(node.getFullStart(), end);
});
}
}
});
示例3: renderReplacedDeclarations
private renderReplacedDeclarations(
code: MagicString,
options: RenderOptions,
{ start = this.start, end = this.end, isNoStatement }: NodeRenderOptions
) {
const separatedNodes = getCommaSeparatedNodesWithBoundaries(
this.declarations,
code,
this.start + this.kind.length,
this.end - (code.original.charCodeAt(this.end - 1) === 59 /*";"*/ ? 1 : 0)
);
let actualContentEnd, renderedContentEnd;
if (/\n\s*$/.test(code.slice(this.start, separatedNodes[0].start))) {
renderedContentEnd = this.start + this.kind.length;
} else {
renderedContentEnd = separatedNodes[0].start;
}
let lastSeparatorPos = renderedContentEnd - 1;
code.remove(this.start, lastSeparatorPos);
let isInDeclaration = false;
let hasRenderedContent = false;
let separatorString = '',
leadingString,
nextSeparatorString;
for (const { node, start, separator, contentEnd, end } of separatedNodes) {
if (
!node.included ||
(isIdentifier(node.id) && isReassignedExportsMember(node.id.variable) && node.init === null)
) {
code.remove(start, end);
continue;
}
leadingString = '';
nextSeparatorString = '';
if (isIdentifier(node.id) && isReassignedExportsMember(node.id.variable)) {
if (hasRenderedContent) {
separatorString += ';';
}
isInDeclaration = false;
} else {
if (
options.format === 'system' &&
node.init !== null &&
isIdentifier(node.id) &&
node.id.variable.exportName
) {
code.prependLeft(
node.init.start,
`exports('${node.id.variable.safeExportName || node.id.variable.exportName}', `
);
nextSeparatorString += ')';
}
if (isInDeclaration) {
separatorString += ',';
} else {
if (hasRenderedContent) {
separatorString += ';';
}
leadingString += `${this.kind} `;
isInDeclaration = true;
}
}
if (renderedContentEnd === lastSeparatorPos + 1) {
code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString + leadingString);
} else {
code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString);
code.appendLeft(renderedContentEnd, leadingString);
}
node.render(code, options);
actualContentEnd = contentEnd;
renderedContentEnd = end;
hasRenderedContent = true;
lastSeparatorPos = separator;
separatorString = nextSeparatorString;
}
if (hasRenderedContent) {
this.renderDeclarationEnd(
code,
separatorString,
lastSeparatorPos,
actualContentEnd,
renderedContentEnd,
!isNoStatement
);
} else {
code.remove(start, end);
}
}