本文整理匯總了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);
}
}