本文整理汇总了TypeScript中source-mutation.createStringMutation函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createStringMutation函数的具体用法?TypeScript createStringMutation怎么用?TypeScript createStringMutation使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createStringMutation函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: parseModuleSource
export const editPaperclipSource = (content: string, mutation: Mutation<PCExpression>): StringMutation[] => {
const result = parseModuleSource(content);
// source is deprecated
const targetNode = findTargetNode(result.root, mutation.target.location || mutation.target["source"]);
if (mutation.target["source"]) {
console.warn(`Mutation target does not match expected type.`);
}
if (!targetNode) {
return [createStringMutation(0, 0, ``)]
}
// switch(mutation.type) {
// case UPDATE_VALUE_NODE: {
// return editNodeValue(targetNode as PCTextNode, mutation as SetValueMutation<any>);
// }
// case SET_ELEMENT_ATTRIBUTE_EDIT: {
// return editElementAttribute(targetNode, mutation as SetPropertyMutation<any>);
// }
// case REMOVE_CHILD_NODE_EDIT: {
// return removeChildAt(targetNode as PCParent, (mutation as RemoveChildMutation<any, any>).index);
// }
// case INSERT_CHILD_NODE_EDIT: {
// return insertChild(targetNode as PCParent, mutation as RemoveChildMutation<any, any>, content);
// }
// case INSERT_HTML_EDIT: {
// return insertHTML(targetNode as PCParent, mutation as InsertHTMLMutation<any>, content);
// }
// case PC_REMOVE_CHILD_NODE: {
// return removeChildAt(targetNode as PCParent, (mutation as PCRemoveChildNodeMutation).index);
// }
// case PC_REMOVE_NODE: {
// return removeNode(targetNode);
// }
// case CSS_INSERT_CSS_RULE_TEXT: {
// // TODO
// }
// case CSS_PARENT_DELETE_RULE: {
// // TODO
// }
// case CSS_STYLE_RULE_SET_SELECTOR_TEXT: {
// // TODO
// }
// case CSS_STYLE_RULE_SET_STYLE_PROPERTY: {
// // TODO
// }
// }
return [createStringMutation(0, 0, ``)];
};
开发者ID:cryptobuks,项目名称:tandem,代码行数:56,代码来源:edit.ts
示例2:
const insertHTML = (parent: PCParent, { childIndex, html }: any, source: string) => {
if (parent.type === PCExpressionType.SELF_CLOSING_ELEMENT) {
const parentElement = parent as any as PCSelfClosingElement;
return [createStringMutation(eatWhitespace(parentElement.location.end.pos - 2, source), parentElement.location.end.pos, ">" + html + `</${parentElement.name}>`)];
}
const beforeChild = parent.childNodes[childIndex];
if (!beforeChild) {
const parentElement = parent as PCElement;
return [createStringMutation(parentElement.startTag.location.end.pos, parentElement.startTag.location.end.pos, html)];
}
return [createStringMutation(beforeChild.location.start.pos, beforeChild.location.start.pos, html)];
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:12,代码来源:edit.ts
示例3: if
const editElementAttribute = (target: PCExpression, mutation: SetPropertyMutation<any>) => {
let startTag: PCSelfClosingElement | PCStartTag;
if (target.type === PCExpressionType.SELF_CLOSING_ELEMENT) {
startTag = target as PCSelfClosingElement;
} else if (target.type === PCExpressionType.ELEMENT) {
startTag = (target as PCElement).startTag;
}
let found;
let mutations: StringMutation[] = [];
const mutateAttrName = mutation.name;
const mutateAttrValue = mutation.newValue && `"${mutation.newValue}"`;
for (const attribute of startTag.attributes) {
// TODO - need to consider spreads
const attr = attribute as PCAttribute;
if (attr.name === mutateAttrName) {
found = true;
// if the attribute value is undefined, then remove it
if (!mutateAttrValue) {
// remove the whitespace before attribute
return [createStringMutation(attr.location.start.pos - 1, attr.location.end.pos, ``)];
} else {
return [createStringMutation(attr.value.location.start.pos, attr.value.location.end.pos, mutateAttrValue)];
}
}
}
if (!found) {
const insertIndex = startTag.location.start.pos + startTag.name.length + 1;
return [createStringMutation(insertIndex, insertIndex, mutation.newValue === true ? mutateAttrName : ` ${mutateAttrName}=${mutateAttrValue}`)];
}
};
开发者ID:cryptobuks,项目名称:tandem,代码行数:40,代码来源:edit.ts
示例4: createStringMutation
const editStyleRuleDeclaration = (target: CSSStyleRule, { newValue }: SetPropertyMutation<any>) => {
const prettyStyleText = newValue.split(/\s*;\s*/g).join(";\n");
// not tested
return createStringMutation(
target.location.start.pos,
target.location.end.pos + 1,
`${target.selectorText.trim()} {
${prettyStyleText}
}`
);
}
开发者ID:cryptobuks,项目名称:tandem,代码行数:13,代码来源:edit.ts
注:本文中的source-mutation.createStringMutation函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论