當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。