本文整理汇总了TypeScript中babel-types.jSXIdentifier函数的典型用法代码示例。如果您正苦于以下问题:TypeScript jSXIdentifier函数的具体用法?TypeScript jSXIdentifier怎么用?TypeScript jSXIdentifier使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了jSXIdentifier函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: buildBlockElement
export function buildBlockElement () {
return t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier('block'), []),
t.jSXClosingElement(t.jSXIdentifier('block')),
[]
)
}
示例2: buildBlockElement
export function buildBlockElement (attrs: t.JSXAttribute[] = []) {
const blockName = Adapter.type === Adapters.quickapp ? 'div' : 'block'
return t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier(blockName), attrs),
t.jSXClosingElement(t.jSXIdentifier(blockName)),
[]
)
}
示例3: buildRefTemplate
export function buildRefTemplate (name: string, refName?: string, loop?: boolean) {
return t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier('template'), [
t.jSXAttribute(t.jSXIdentifier('is'), t.stringLiteral(name)),
t.jSXAttribute(t.jSXIdentifier('data'), t.stringLiteral(`{{...${refName ? `${loop ? '' : '$$'}${refName}` : '__data'}}}`))
]),
t.jSXClosingElement(t.jSXIdentifier('template')),
[]
)
}
示例4: replaceJSXTextWithTextComponent
export function replaceJSXTextWithTextComponent (path: NodePath<t.JSXText | t.JSXExpressionContainer>) {
const parent = path.findParent(p => p.isJSXElement())
if (parent && parent.isJSXElement() && t.isJSXIdentifier(parent.node.openingElement.name) && parent.node.openingElement.name.name !== 'Text') {
path.replaceWith(t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier('Text'), []),
t.jSXClosingElement(t.jSXIdentifier('Text')),
[path.isJSXText() ? t.jSXText(path.node.value) : path.node]
))
}
}
示例5: buildRefTemplate
export function buildRefTemplate (name: string, refName?: string, loop?: boolean, key?: t.JSXAttribute) {
const attrs = [
t.jSXAttribute(t.jSXIdentifier('is'), t.stringLiteral(name)),
t.jSXAttribute(t.jSXIdentifier('data'), t.stringLiteral(`{{...${refName ? `${loop ? '' : '$$'}${refName}` : '__data'}}}`))
]
if (key) {
attrs.push(key)
}
return t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier('template'), attrs),
t.jSXClosingElement(t.jSXIdentifier('template')),
[]
)
}
示例6: setJSXAttr
export function setJSXAttr (
jsx: t.JSXElement,
name: string,
value?: t.StringLiteral | t.JSXExpressionContainer
) {
jsx.openingElement.attributes.push(
t.jSXAttribute(t.jSXIdentifier(name), value)
)
}
示例7: Error
.forEach(p => {
const node = p.node
if (node.name.name === WX_FOR_ITEM) {
if (!node.value || !t.isStringLiteral(node.value)) {
throw new Error(WX_FOR_ITEM + ' 的值必须是一个字符串')
}
item = node.value
p.remove()
}
if (node.name.name === WX_FOR_INDEX) {
if (!node.value || !t.isStringLiteral(node.value)) {
throw new Error(WX_FOR_INDEX + ' 的值必须是一个字符串')
}
index = node.value
p.remove()
}
if (node.name.name === WX_KEY) {
p.get('name').replaceWith(t.jSXIdentifier('key'))
}
})
示例8: parseAttribute
function parseAttribute (attr: Attribute) {
const { key, value } = attr
let jsxValue: null | t.JSXExpressionContainer | t.StringLiteral = null
if (value) {
const { type, content } = parseContent(value)
jsxValue =
type === 'raw'
? t.stringLiteral(content)
: t.jSXExpressionContainer(buildTemplate(content))
}
const jsxKey = handleAttrKey(key)
if (/^on[A-Z]/.test(jsxKey) && jsxValue && t.isStringLiteral(jsxValue)) {
jsxValue = t.jSXExpressionContainer(
t.memberExpression(t.thisExpression(), t.identifier(jsxValue.value))
)
}
return t.jSXAttribute(t.jSXIdentifier(jsxKey), jsxValue)
}
示例9: setJSXAttr
export function setJSXAttr (
jsx: t.JSXElement,
name: string,
value?: t.StringLiteral | t.JSXExpressionContainer | t.JSXElement,
path?: NodePath<t.JSXElement>
) {
const element = jsx.openingElement
if (!t.isJSXIdentifier(element.name)) {
return
}
if (element.name.name === 'Block' || element.name.name === 'block' || !path) {
jsx.openingElement.attributes.push(
t.jSXAttribute(t.jSXIdentifier(name), value)
)
} else {
const block = buildBlockElement()
setJSXAttr(block, name, value)
block.children = [jsx]
path.node = block
}
}
示例10: parseElement
function parseElement (element: Element): t.JSXElement {
const tagName = t.jSXIdentifier(allCamelCase(element.tagName))
if (DEFAULT_Component_SET.has(tagName.name)) {
usedComponents.add(tagName.name)
}
let attributes = element.attributes
if (tagName.name === 'Template') {
let isSpread = false
attributes = attributes.map(attr => {
if (attr.key === 'data') {
const value = attr.value || ''
const content = parseContent(value)
if (content.type === 'expression') {
isSpread = true
const str = content.content
if (str.includes('...') && str.includes(',')) {
attr.value = `{{${str.slice(1, str.length - 1)}}}`
} else {
attr.value = `{{${str.slice(str.includes('...') ? 4 : 1 , str.length - 1)}}}`
}
} else {
attr.value = content.content
}
}
return attr
})
if (isSpread) {
attributes.push({
key: 'spread',
value: null
})
}
}
return t.jSXElement(
t.jSXOpeningElement(tagName, attributes.map(parseAttribute)),
t.jSXClosingElement(tagName),
removEmptyTextAndComment(element.children).map((el) => parseNode(el, element.tagName)),
false
)
}