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