当前位置: 首页>>代码示例>>TypeScript>>正文


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

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


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

示例1:

 imports.forEach(i => {
   if (!i.isDefault) {
     output.appendLeft(0, `import * as ${i.qualifier} from '${i.specifier}';\n`);
   } else {
     output.appendLeft(0, `import ${i.qualifier} from '${i.specifier}';\n`);
   }
 });
开发者ID:zackarychapple,项目名称:angular,代码行数:7,代码来源:esm_renderer.ts

示例2: add_indentation

export function add_indentation(code: MagicString, node: Node, levels = 1) {
	const base_indent = code.getIndentString();
	const indent = repeat(base_indent, levels);
	const pattern = /\n/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.appendLeft(index + 1, indent);
	}
}
开发者ID:StevenWeathers,项目名称:svelte,代码行数:26,代码来源:indentation.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: 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

示例5: encapsulateBlock

		function encapsulateBlock(block: Block) {
			let i = block.selectors.length;
			while (i--) {
				const selector = block.selectors[i];
				if (selector.type === 'PseudoElementSelector' || selector.type === 'PseudoClassSelector') continue;

				if (selector.type === 'TypeSelector' && selector.name === '*') {
					code.overwrite(selector.start, selector.end, attr);
				} else {
					code.appendLeft(selector.end, attr);
				}

				break;
			}

			i = block.selectors.length;
			while (i--) {
				const selector = block.selectors[i];

				if (selector.type === 'RefSelector') {
					code.overwrite(selector.start, selector.end, `[svelte-ref-${selector.name}]`, {
						contentOnly: true,
						storeName: false
					});
				}
			}
		}
开发者ID:kristoferbaxter,项目名称:svelte,代码行数:27,代码来源:Selector.ts

示例6: addImports

 /**
  *  Add the imports at the top of the file
  */
 addImports(
     output: MagicString, imports: {specifier: string; qualifier: string;}[],
     sf: ts.SourceFile): void {
   const insertionPoint = findEndOfImports(sf);
   const renderedImports =
       imports.map(i => `import * as ${i.qualifier} from '${i.specifier}';\n`).join('');
   output.appendLeft(insertionPoint, renderedImports);
 }
开发者ID:marclaval,项目名称:angular,代码行数:11,代码来源:esm_renderer.ts

示例7: addDefinitions

 /**
  * Add the definitions to each decorated class
  */
 addDefinitions(output: MagicString, compiledClass: CompiledClass, definitions: string): void {
   const classSymbol = this.host.getClassSymbol(compiledClass.declaration);
   if (!classSymbol) {
     throw new Error(`Compiled class does not have a valid symbol: ${compiledClass.name}`);
   }
   const insertionPoint = classSymbol.valueDeclaration !.getEnd();
   output.appendLeft(insertionPoint, '\n' + definitions);
 }
开发者ID:marclaval,项目名称:angular,代码行数:11,代码来源:esm_renderer.ts

示例8: render

	render(code: MagicString, options: RenderOptions) {
		this.left.render(code, options);
		this.right.render(code, options);
		if (options.format === 'system' && this.left.variable && this.left.variable.exportName) {
			code.prependLeft(
				code.original.indexOf('=', this.left.end) + 1,
				` exports('${this.left.variable.exportName}',`
			);
			code.appendLeft(this.right.end, `)`);
		}
	}
开发者ID:tivac,项目名称:rollup,代码行数:11,代码来源:AssignmentExpression.ts

示例9: renderDeclarationEnd

	private renderDeclarationEnd(
		code: MagicString,
		separatorString: string,
		lastSeparatorPos: number,
		actualContentEnd: number,
		renderedContentEnd: number,
		addSemicolon: boolean,
		systemPatternExports: Variable[]
	): void {
		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);
		}
		if (systemPatternExports.length > 0) {
			code.appendLeft(renderedContentEnd, ' ' + getSystemExportStatement(systemPatternExports));
		}
	}
开发者ID:robbie-mac,项目名称:rollup,代码行数:39,代码来源:VariableDeclaration.ts

示例10: addConstants

 addConstants(output: MagicString, constants: string, file: ts.SourceFile): void {
   if (constants === '') {
     return;
   }
   const insertionPoint = file.statements.reduce((prev, stmt) => {
     if (ts.isImportDeclaration(stmt) || ts.isImportEqualsDeclaration(stmt) ||
         ts.isNamespaceImport(stmt)) {
       return stmt.getEnd();
     }
     return prev;
   }, 0);
   output.appendLeft(insertionPoint, '\n' + constants + '\n');
 }
开发者ID:felixfbecker,项目名称:angular,代码行数:13,代码来源:esm_renderer.ts


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