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


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

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


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

示例1: addConstants

  addConstants(output: MagicString, constants: string, file: ts.SourceFile): void {
    if (constants === '') {
      return;
    }
    const insertionPoint = findEndOfImports(file);

    // Append the constants to the right of the insertion point, to ensure they get ordered after
    // added imports (those are appended left to the insertion point).
    output.appendRight(insertionPoint, '\n' + constants + '\n');
  }
开发者ID:marclaval,项目名称:angular,代码行数:10,代码来源:esm_renderer.ts

示例2: render

	render (code: MagicString, options: RenderOptions) {
		if (!this.module.graph.treeshake || this.included) {
			if (options.systemBindings && this.id.variable.exportName) {
				code.appendRight(this.end, ` exports('${this.id.variable.exportName}', ${this.id.variable.getName()});`);
			}
			super.render(code, options);
		} else {
			code.remove(
				this.leadingCommentStart || this.start,
				this.next || this.end
			);
		}
	}
开发者ID:zhyt201,项目名称:rollup,代码行数:13,代码来源:ClassDeclaration.ts

示例3: render

	render(
		code: MagicString,
		options: RenderOptions,
		{ renderedParentType }: NodeRenderOptions = BLANK
	) {
		super.render(code, options);
		if (
			renderedParentType === NodeType.ExpressionStatement &&
			this.callee.type === NodeType.FunctionExpression
		) {
			code.appendRight(this.start, '(');
			code.prependLeft(this.end, ')');
		}
	}
开发者ID:robbie-mac,项目名称:rollup,代码行数:14,代码来源:CallExpression.ts

示例4: escape

/**
 * Inserts string escape characters before certain characters/strings to be
 * escaped.
 *
 * The skipPattern parameter describes which already-escaped characters to skip
 * over. For normal strings, if we see any backslash, we skip it and the next
 * character, but for heregexes, we only skip a backslash followed by
 * whitespace.
 */
export default function escape(
  source: string,
  patcher: MagicString,
  skipPattern: RegExp,
  escapeStrings: Array<string>,
  start: number,
  end: number
): void {
  for (let i = start; i < end; i++) {
    if (skipPattern.test(source.slice(i, end))) {
      i++;
    } else if (escapeStrings.some(str => source.slice(i, i + str.length) === str)) {
      patcher.appendRight(i, '\\');
    }
  }
}
开发者ID:alangpierce,项目名称:decaffeinate,代码行数:25,代码来源:escape.ts

示例5: render

	render (code: MagicString, options: RenderOptions) {
		if (!this.module.graph.treeshake) {
			super.render(code, options);
		} else {
			if (this.testValue === UNKNOWN_VALUE) {
				super.render(code, options);
			} else {
				const branchToRetain = this.testValue
					? this.consequent
					: this.alternate;

				code.remove(this.start, branchToRetain.start);
				code.remove(branchToRetain.end, this.end);
				if (branchToRetain.type === NodeType.SequenceExpression) {
					code.prependLeft(branchToRetain.start, '(');
					code.appendRight(branchToRetain.end, ')');
				}
				branchToRetain.render(code, options);
			}
		}
	}
开发者ID:zhyt201,项目名称:rollup,代码行数:21,代码来源:ConditionalExpression.ts

示例6: translateType

 dtsClass.compilation.forEach(declaration => {
   const type = translateType(declaration.type, importManager);
   const newStatement = `    static ${declaration.name}: ${type};\n`;
   outputText.appendRight(endOfClass - 1, newStatement);
 });
开发者ID:felixfbecker,项目名称:angular,代码行数:5,代码来源:renderer.ts

示例7: updateJsonWorkspace


//.........这里部分代码省略.........
        let removalIndex = -1;
        if (node.kind === 'object') {
          removalIndex = elements.findIndex(e => {
            return typeof e != 'string' && e.kind === 'keyvalue' && e.key.value === propertyOrIndex;
          });
        } else if (node.kind === 'array') {
          removalIndex = +propertyOrIndex;
        }
        if (removalIndex === -1) {
          continue;
        }

        const nodeToRemove = elements[removalIndex];
        if (typeof nodeToRemove === 'string') {
          // synthetic
          elements.splice(removalIndex, 1);
          continue;
        }

        if (elements.length - 1 === removalIndex) {
          // If the element is a terminal element remove the otherwise trailing comma
          const commaIndex = findPrecedingComma(nodeToRemove, data.original);
          if (commaIndex !== -1) {
            data.remove(commaIndex, commaIndex + 1);
            removedCommas.add(commaIndex);
          }
        }
        data.remove(
          findFullStart(nodeToRemove, data.original),
          findFullEnd(nodeToRemove, data.original),
        );
        elements.splice(removalIndex, 1);
        break;
      case 'replace':
        let nodeToReplace;
        if (node.kind === 'keyvalue') {
          nodeToReplace = node.value;
        } else if (node.kind === 'array') {
          nodeToReplace = elements[+propertyOrIndex];
          if (typeof nodeToReplace === 'string') {
            // Was already modified. This is already handled.
            continue;
          }
        } else {
          continue;
        }

        nodeChanges.delete(nodeToReplace);

        data.overwrite(
          nodeToReplace.start.offset,
          nodeToReplace.end.offset,
          stringify(jsonValue, multiline, depth, indent),
        );
        break;
    }
  }

  for (const [node, elements] of nodeChanges.entries()) {
    let parentPoint = 1 + data.original.indexOf(
      node.kind === 'array' ? '[' : '{',
      node.start.offset,
    );

    // Short-circuit for simple case
    if (elements.length === 1 && typeof elements[0] === 'string') {
      data.appendRight(parentPoint, elements[0] as string);
      continue;
    }

    // Combine adjecent element additions to minimize/simplify insertions
    const optimizedElements: typeof elements = [];
    for (let i = 0; i < elements.length; ++i) {
      const element = elements[i];
      if (typeof element === 'string' && i > 0 && typeof elements[i - 1] === 'string') {
        optimizedElements[optimizedElements.length - 1] += ',' + element;
      } else {
        optimizedElements.push(element);
      }
    }

    let prefixComma = false;
    for (const element of optimizedElements) {
      if (typeof element === 'string') {
        data.appendRight(
          parentPoint,
          (prefixComma ? ',' : '') + element,
        );
      } else {
        parentPoint = findFullEnd(element, data.original);
        prefixComma = data.original[parentPoint - 1] !== ',' || removedCommas.has(parentPoint - 1);
      }
    }

  }

  const result = data.toString();

  return result;
}
开发者ID:angular,项目名称:angular-cli,代码行数:101,代码来源:writer.ts


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