• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript magic-string.remove函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中magic-string.remove函数的典型用法代码示例。如果您正苦于以下问题:TypeScript remove函数的具体用法?TypeScript remove怎么用?TypeScript remove使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了remove函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: renderDeclarationEnd

	private renderDeclarationEnd (
		code: MagicString,
		separatorString: string,
		lastSeparatorPos: number,
		actualContentEnd: number,
		renderedContentEnd: number,
		addSemicolon: boolean
	) {
		if (code.original.charCodeAt(this.end - 1) === 59 /*";"*/) {
			code.remove(this.end - 1, this.end);
		}
		if (addSemicolon) {
			separatorString += ';';
		}
		if (lastSeparatorPos !== null) {
			if (
				code.original.charCodeAt(actualContentEnd - 1) === 10 /*"\n"*/
				&& (code.original.charCodeAt(this.end) === 10 /*"\n"*/ || code.original.charCodeAt(this.end) === 13 /*"\r"*/)
			) {
				actualContentEnd--;
				if (code.original.charCodeAt(actualContentEnd) === 13 /*"\r"*/) {
					actualContentEnd--;
				}
			}
			if (actualContentEnd === lastSeparatorPos + 1) {
				code.overwrite(lastSeparatorPos, renderedContentEnd, separatorString);
			} else {
				code.overwrite(lastSeparatorPos, lastSeparatorPos + 1, separatorString);
				code.remove(actualContentEnd, renderedContentEnd);
			}
		} else {
			code.appendLeft(renderedContentEnd, separatorString);
		}
		return separatorString;
	}
开发者ID:joeldenning,项目名称:rollup,代码行数:35,代码来源:VariableDeclaration.ts


示例2: render

	render(code: MagicString, options: RenderOptions) {
		// Note that unknown test values are always included
		if (
			!this.test.included &&
			(this.testValue
				? this.alternate === null || !this.alternate.included
				: !this.consequent.included)
		) {
			const singleRetainedBranch = this.testValue ? this.consequent : this.alternate;
			code.remove(this.start, singleRetainedBranch.start);
			code.remove(singleRetainedBranch.end, this.end);
			removeAnnotations(this, code);
			singleRetainedBranch.render(code, options);
		} else {
			if (this.test.included) {
				this.test.render(code, options);
			} else {
				code.overwrite(this.test.start, this.test.end, this.testValue ? 'true' : 'false');
			}
			if (this.consequent.included) {
				this.consequent.render(code, options);
			} else {
				code.overwrite(this.consequent.start, this.consequent.end, ';');
			}
			if (this.alternate !== null) {
				if (this.alternate.included) {
					this.alternate.render(code, options);
				} else {
					code.remove(this.consequent.end, this.alternate.end);
				}
			}
		}
	}
开发者ID:robbie-mac,项目名称:rollup,代码行数:33,代码来源:IfStatement.ts


示例3: render

	render (code: MagicString, options: RenderOptions) {
		if (!this.module.graph.treeshake) {
			super.render(code, options);
		} else {
			const last = this.expressions[this.expressions.length - 1];
			last.render(code, options);

			if (
				this.parent.type === NodeType.CallExpression &&
				last.type === NodeType.MemberExpression &&
				this.expressions.length > 1
			) {
				this.expressions[0].included = true;
			}

			const included = this.expressions
				.slice(0, this.expressions.length - 1)
				.filter(expression => expression.included);
			if (included.length === 0) {
				code.remove(this.start, last.start);
				code.remove(last.end, this.end);
			} else {
				let previousEnd = this.start;
				for (const expression of included) {
					expression.render(code, options);
					code.remove(previousEnd, expression.start);
					code.appendLeft(expression.end, ', ');
					previousEnd = expression.end;
				}

				code.remove(previousEnd, last.start);
				code.remove(last.end, this.end);
			}
		}
	}
开发者ID:joeldenning,项目名称:rollup,代码行数:35,代码来源:SequenceExpression.ts


示例4: render

	render (code: MagicString, options: RenderOptions) {
		if (this.declaration) {
			code.remove(this.start, this.declaration.start);
			this.declaration.render(code, options);
		} else {
			const start = this.leadingCommentStart || this.start;
			const end = this.next || this.end;
			code.remove(start, end);
		}
	}
开发者ID:zhyt201,项目名称:rollup,代码行数:10,代码来源:ExportNamedDeclaration.ts


示例5: treeshakeNode

export function treeshakeNode(node: Node, code: MagicString, start: number, end: number) {
	code.remove(start, end);
	if (node.annotations) {
		for (const annotation of node.annotations) {
			if (annotation.start < start) {
				code.remove(annotation.start, annotation.end);
			} else {
				return;
			}
		}
	}
}
开发者ID:robbie-mac,项目名称:rollup,代码行数:12,代码来源:treeshakeNode.ts


示例6: render

	render (code: MagicString, options: RenderOptions) {
		if (this.module.graph.treeshake) {
			if (this.testValue === UNKNOWN_VALUE) {
				super.render(code, options);
			} else {
				code.overwrite(
					this.test.start,
					this.test.end,
					JSON.stringify(this.testValue)
				);

				// TODO if no block-scoped declarations, remove enclosing
				// curlies and dedent block (if there is a block)

				if (this.hoistedVars) {
					const names = this.hoistedVars
						.map(name => {
							const variable = this.scope.findVariable(name);
							return variable.included ? variable.getName() : null;
						})
						.filter(Boolean);

					if (names.length > 0) {
						code.appendLeft(this.start, `var ${names.join(', ')};\n\n`);
					}
				}

				if (this.testValue) {
					code.remove(this.start, this.consequent.start);
					code.remove(this.consequent.end, this.end);
					this.consequent.render(code, options);
				} else {
					code.remove(
						this.start,
						this.alternate ? this.alternate.start : this.next || this.end
					);

					if (this.alternate) {
						this.alternate.render(code, options);
					} else if (statementsWithIfStatements.has(this.parent.type)) {
						code.prependRight(this.start, '{}');
					}
				}
			}
		} else {
			super.render(code, options);
		}
	}
开发者ID:zhyt201,项目名称:rollup,代码行数:48,代码来源:IfStatement.ts


示例7: remove_indentation

export function remove_indentation(code: MagicString, node: Node) {
	const indent = code.getIndentString();
	const pattern = new RegExp(`^${indent}`, 'gm');

	const excluded = [];

	walk(node, {
		enter(node) {
			if (node.type === 'TemplateElement') {
				excluded.push(node);
			}
		}
	});

	const str = code.original.slice(node.start, node.end);

	let match;
	while (match = pattern.exec(str)) {
		const index = node.start + match.index;
		while (excluded[0] && excluded[0].end < index) excluded.shift();
		if (excluded[0] && excluded[0].start < index) continue;

		code.remove(index, index + indent.length);
	}
}
开发者ID:StevenWeathers,项目名称:svelte,代码行数:25,代码来源:indentation.ts


示例8: removeNode

export function removeNode(code: MagicString, parent: Node, node: Node) {
	const key = keys[parent.type];
	const offset = offsets[parent.type];
	if (!key || !offset) throw new Error(`not implemented: ${parent.type}`);

	const list = parent[key];
	const i = list.indexOf(node);
	if (i === -1) throw new Error('node not in list');

	let a;
	let b;

	if (list.length === 1) {
		// remove everything, leave {}
		a = parent.start + offset[0];
		b = parent.end + offset[1];
	} else if (i === 0) {
		// remove everything before second node, including comments
		a = parent.start + offset[0];
		while (/\s/.test(code.original[a])) a += 1;

		b = list[i].end;
		while (/[\s,]/.test(code.original[b])) b += 1;
	} else {
		// remove the end of the previous node to the end of this one
		a = list[i - 1].end;
		b = node.end;
	}

	code.remove(a, b);
	list.splice(i, 1);
	return;
}
开发者ID:kristoferbaxter,项目名称:svelte,代码行数:33,代码来源:removeNode.ts


示例9: renderStatementList

export function renderStatementList (statements: Node[], code: MagicString, start: number, end: number, options: RenderOptions) {
	if (statements.length === 0) return;
	let currentNode, currentNodeStart, currentNodeNeedsBoundaries, nextNodeStart;
	let nextNode = statements[0];
	let nextNodeNeedsBoundaries = !nextNode.included || nextNode.needsBoundaries;
	if (nextNodeNeedsBoundaries) {
		nextNodeStart = start + findFirstLineBreakOutsideComment(code.original.slice(start, nextNode.start)) + 1;
	}

	for (let nextIndex = 1; nextIndex <= statements.length; nextIndex++) {
		currentNode = nextNode;
		currentNodeStart = nextNodeStart;
		currentNodeNeedsBoundaries = nextNodeNeedsBoundaries;
		nextNode = statements[nextIndex];
		nextNodeNeedsBoundaries = nextNode === undefined ? false : !nextNode.included || nextNode.needsBoundaries;
		if (currentNodeNeedsBoundaries || nextNodeNeedsBoundaries) {
			nextNodeStart = currentNode.end + findFirstLineBreakOutsideComment(
				code.original.slice(currentNode.end, nextNode === undefined ? end : nextNode.start)
			) + 1;
			if (currentNode.included) {
				currentNodeNeedsBoundaries
					? currentNode.render(code, options, { start: currentNodeStart, end: nextNodeStart })
					: currentNode.render(code, options);
			} else {
				code.remove(currentNodeStart, nextNodeStart);
			}
		} else {
			currentNode.render(code, options);
		}
	}
}
开发者ID:joeldenning,项目名称:rollup,代码行数:31,代码来源:renderHelpers.ts


示例10:

 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



注:本文中的magic-string.remove函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript magic-string.slice函数代码示例发布时间:2022-05-25
下一篇:
TypeScript magic-string.prependLeft函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap