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


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

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


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

示例1: 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

示例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.resolutionNamespace) {
			const _ = options.compact ? '' : ' ';
			const s = options.compact ? '' : ';';
			code.overwrite(
				this.parent.start,
				this.parent.end,
				`Promise.resolve().then(function${_}()${_}{${_}return ${this.resolutionNamespace}${s}${_}})`
			);
			return;
		}

		const importMechanism = getDynamicImportMechanism(options);
		if (importMechanism) {
			const leftMechanism =
				(this.resolutionInterop && importMechanism.interopLeft) || importMechanism.left;
			const leftMechanismEnd =
				findFirstOccurrenceOutsideComment(code.original, '(', this.parent.callee.end) + 1;
			code.overwrite(this.parent.start, leftMechanismEnd, leftMechanism);

			const rightMechanism =
				(this.resolutionInterop && importMechanism.interopRight) || importMechanism.right;
			code.overwrite(this.parent.end - 1, this.parent.end, rightMechanism);
		}
	}
开发者ID:robbie-mac,项目名称:rollup,代码行数:25,代码来源:Import.ts

示例4: render

	render(code: MagicString, options: RenderOptions) {
		this.argument.render(code, options);
		const variable = this.argument.variable;
		if (options.format === 'system' && variable && variable.exportName) {
			const name = variable.getName();
			if (this.prefix) {
				code.overwrite(
					this.start,
					this.end,
					`exports('${variable.exportName}', ${this.operator}${name})`
				);
			} else {
				let op;
				switch (this.operator) {
					case '++':
						op = `${name} + 1`;
						break;
					case '--':
						op = `${name} - 1`;
						break;
				}
				code.overwrite(
					this.start,
					this.end,
					`(exports('${variable.exportName}', ${op}), ${name}${this.operator})`
				);
			}
		}
	}
开发者ID:robbie-mac,项目名称:rollup,代码行数:29,代码来源:UpdateExpression.ts

示例5: 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

示例6: MagicString

		usedHelpers.forEach(key => {
			const str = shared[key];
			const code = new MagicString(str);
			const expression = parseExpressionAt(str, 0);

			let { scope } = annotateWithScopes(expression);

			walk(expression, {
				enter(node: Node, parent: Node) {
					if (node._scope) scope = node._scope;

					if (
						node.type === 'Identifier' &&
						isReference(node, parent) &&
						!scope.has(node.name)
					) {
						if (node.name in shared) {
							// this helper function depends on another one
							const dependency = node.name;
							usedHelpers.add(dependency);

							const alias = generator.alias(dependency);
							if (alias !== node.name)
								code.overwrite(node.start, node.end, alias);
						}
					}
				},

				leave(node: Node) {
					if (node._scope) scope = scope.parent;
				},
			});

			if (key === 'transitionManager') {
				// special case
				const global = `_svelteTransitionManager`;

				inlineHelpers += `\n\nvar ${generator.alias('transitionManager')} = window.${global} || (window.${global} = ${code});\n\n`;
			} else {
				const alias = generator.alias(expression.id.name);
				if (alias !== expression.id.name)
					code.overwrite(expression.id.start, expression.id.end, alias);

				inlineHelpers += `\n\n${code}`;
			}
		});
开发者ID:kristoferbaxter,项目名称:svelte,代码行数:46,代码来源:index.ts

示例7: renderFinalResolution

	renderFinalResolution(code: MagicString, resolution: string, format: string) {
		if (this.included) {
			if (format === 'amd' && resolution.startsWith("'.") && resolution.endsWith(".js'")) {
				resolution = resolution.slice(0, -4) + "'";
			}
			code.overwrite(this.parent.arguments[0].start, this.parent.arguments[0].end, resolution);
		}
	}
开发者ID:rollup,项目名称:rollup,代码行数:8,代码来源:Import.ts

示例8:

		this.blocks.forEach((block, i) => {
			if (i > 0) {
				if (block.start - c > 1) {
					code.overwrite(c, block.start, block.combinator.name || ' ');
				}
			}

			c = block.end;
		});
开发者ID:kristoferbaxter,项目名称:svelte,代码行数:9,代码来源:Selector.ts

示例9: render

	render (code: MagicString, options: RenderOptions) {
		// if we have the module in the chunk, inline as Promise.resolve(namespace)
		let resolution: string;
		if (this.resolution instanceof NamespaceVariable) {
			// ideally this should be handled like normal tree shaking
			this.resolution.includeVariable();
			code.overwrite(this.parent.start, this.parent.arguments[0].start, 'Promise.resolve().then(function () { return ');
			code.overwrite(this.parent.arguments[0].start, this.parent.arguments[0].end, this.resolution.getName());
			code.overwrite(this.parent.arguments[0].end, this.parent.end, '; })');

		} else if (this.resolution) {
			resolution = this.resolution;

			if (options.importMechanism) {
				const leftMechanism = this.resolutionInterop && options.importMechanism.interopLeft || options.importMechanism.left;
				code.overwrite(this.parent.start, this.parent.arguments[0].start, leftMechanism);
			}

			if (resolution) {
				code.overwrite(this.parent.arguments[0].start, this.parent.arguments[0].end, resolution);
			}

			if (options.importMechanism) {
				const rightMechanism = this.resolutionInterop && options.importMechanism.interopRight || options.importMechanism.right;
				code.overwrite(this.parent.arguments[0].end, this.parent.end, rightMechanism);
			}
		}
	}
开发者ID:zhyt201,项目名称:rollup,代码行数:28,代码来源:Import.ts

示例10: MagicString

  transform: (code: string) => {
    const newContent = new MagicString(code);

    // Walks through every occurrence of a license comment and overwrites it with an empty string.
    for (let pos = -1; (pos = code.indexOf(licenseBanner, pos + 1)) !== -1; null) {
      newContent.overwrite(pos, pos + licenseBanner.length, '');
    }

    return {
      code: newContent.toString(),
      map:  newContent.generateMap({ hires: true })
    };
  }
开发者ID:Chintuz,项目名称:material2,代码行数:13,代码来源:rollup-remove-licenses.ts


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