當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript magic-string.slice函數代碼示例

本文整理匯總了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);
 });
開發者ID:marclaval,項目名稱:angular,代碼行數:7,代碼來源:esm_renderer.ts

示例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);
       });
     }
   }
 });
開發者ID:hulkike,項目名稱:angular,代碼行數:20,代碼來源:esm2015_renderer.ts

示例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);
		}
	}
開發者ID:IvanSanchez,項目名稱:rollup,代碼行數:88,代碼來源:VariableDeclaration.ts


注:本文中的magic-string.slice函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。