本文整理匯總了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`);
}
});
示例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);
}
}
示例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);
}
}
}
示例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;
}
示例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
});
}
}
}
示例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);
}
示例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);
}
示例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, `)`);
}
}
示例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));
}
}
示例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');
}