本文整理汇总了TypeScript中babel-types.jSXOpeningElement函数的典型用法代码示例。如果您正苦于以下问题:TypeScript jSXOpeningElement函数的具体用法?TypeScript jSXOpeningElement怎么用?TypeScript jSXOpeningElement使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了jSXOpeningElement函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: buildBlockElement
export function buildBlockElement () {
return t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier('block'), []),
t.jSXClosingElement(t.jSXIdentifier('block')),
[]
)
}
开发者ID:AlloyTeam,项目名称:Nuclear,代码行数:7,代码来源:jsx.ts
示例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)),
[]
)
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:8,代码来源:jsx.ts
示例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')),
[]
)
}
开发者ID:teachat8,项目名称:taro,代码行数:10,代码来源:jsx.ts
示例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]
))
}
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:10,代码来源:utils.ts
示例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')),
[]
)
}
开发者ID:AlloyTeam,项目名称:Nuclear,代码行数:14,代码来源:jsx.ts
示例6: 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
)
}
开发者ID:YangShaoQun,项目名称:taro,代码行数:40,代码来源:wxml.ts
示例7: parseTemplate
export function parseTemplate (path: NodePath<t.JSXElement>, dirPath: string) {
const openingElement = path.get('openingElement')
const attrs = openingElement.get('attributes')
const is = attrs.find(attr => attr.get('name').isJSXIdentifier({ name: 'is' }))
const data = attrs.find(attr => attr.get('name').isJSXIdentifier({ name: 'data' }))
// const spread = attrs.find(attr => attr.get('name').isJSXIdentifier({ name: 'spread' }))
const name = attrs.find(attr => attr.get('name').isJSXIdentifier({ name: 'name' }))
const refIds = new Set<string>()
if (name) {
const value = name.node.value
if (value === null || !t.isStringLiteral(value)) {
throw new Error('template 的 `name` 属性只能是字符串')
}
const className = pascalName(value.value) + pascalName(basename(dirPath))
path.traverse({
Identifier (p) {
if (!p.isReferencedIdentifier()) {
return
}
const jsxExprContainer = p.findParent(p => p.isJSXExpressionContainer())
if (!jsxExprContainer || !jsxExprContainer.isJSXExpressionContainer()) {
return
}
refIds.add(p.node.name)
}
})
const block = buildBlockElement()
block.children = path.node.children
let render: t.ClassMethod
if (refIds.size === 0) {
// 无状态组件
render = buildRender(block, [], [])
} else if (refIds.size === 1) {
// 只有一个数据源
render = buildRender(block, [], Array.from(refIds), Array.from(refIds)[0])
} else {
// 使用 ...spread
render = buildRender(block, [], Array.from(refIds), [])
}
const classDecl = t.classDeclaration(
t.identifier(className),
t.memberExpression(t.identifier('Taro'), t.identifier('Component')),
t.classBody([render!]),
[]
)
path.remove()
return {
name: className,
ast: classDecl
}
} else if (is) {
const value = is.node.value
if (!value) {
throw new Error('template 的 `is` 属性不能为空')
}
if (t.isStringLiteral(value)) {
const className = pascalName(value.value)
let attributes: t.JSXAttribute[] = []
if (data) {
attributes.push(data.node)
}
path.replaceWith(t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier(className), attributes),
t.jSXClosingElement(t.jSXIdentifier(className)),
[],
true
))
} else if (t.isJSXExpressionContainer(value)) {
if (t.isStringLiteral(value.expression)) {
const className = pascalName(value.expression.value)
let attributes: t.JSXAttribute[] = []
if (data) {
attributes.push(data.node)
}
path.replaceWith(t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier(className), attributes),
t.jSXClosingElement(t.jSXIdentifier(className)),
[],
true
))
} else if (t.isConditional(value.expression)) {
const { test, consequent, alternate } = value.expression
if (!t.isStringLiteral(consequent) || !t.isStringLiteral(alternate)) {
throw new Error('当 template is 标签是三元表达式时,他的两个值都必须为字符串')
}
let attributes: t.JSXAttribute[] = []
if (data) {
attributes.push(data.node)
}
const block = buildBlockElement()
block.children = [t.jSXExpressionContainer(t.conditionalExpression(
test,
t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier('Template'), attributes.concat(
[t.jSXAttribute(t.jSXIdentifier('is'), consequent)]
)),
t.jSXClosingElement(t.jSXIdentifier('Template')),
[],
//.........这里部分代码省略.........
开发者ID:topud,项目名称:taro,代码行数:101,代码来源:template.ts
示例8: parseTemplate
export function parseTemplate (path: NodePath<t.JSXElement>, dirPath: string) {
if (!path.container) {
return
}
const openingElement = path.get('openingElement')
const attrs = openingElement.get('attributes')
const is = attrs.find(attr => attr.get('name').isJSXIdentifier({ name: 'is' }))
const data = attrs.find(attr => attr.get('name').isJSXIdentifier({ name: 'data' }))
// const spread = attrs.find(attr => attr.get('name').isJSXIdentifier({ name: 'spread' }))
const name = attrs.find(attr => attr.get('name').isJSXIdentifier({ name: 'name' }))
const refIds = new Set<string>()
const loopIds = new Set<string>()
let imports: any[] = []
if (name) {
const value = name.node.value
if (value === null || !t.isStringLiteral(value)) {
throw new Error('template 的 `name` 属性只能是字符串')
}
const className = buildTemplateName(value.value)
path.traverse(createWxmlVistor(loopIds, refIds, dirPath, [], imports))
const firstId = Array.from(refIds)[0]
refIds.forEach(id => {
if (loopIds.has(id) && id !== firstId) {
refIds.delete(id)
}
})
const block = buildBlockElement()
block.children = path.node.children
let render: t.ClassMethod
if (refIds.size === 0) {
// 无状态组件
render = buildRender(block, [], [])
} else if (refIds.size === 1) {
// 只有一个数据源
render = buildRender(block, [], Array.from(refIds), firstId)
} else {
// 使用 ...spread
render = buildRender(block, [], Array.from(refIds), [])
}
const classProp = t.classProperty(t.identifier('options'), t.objectExpression([
t.objectProperty(
t.identifier('addGlobalClass'),
t.booleanLiteral(true)
)
])) as any
classProp.static = true
const classDecl = t.classDeclaration(
t.identifier(className),
t.memberExpression(t.identifier('Taro'), t.identifier('Component')),
t.classBody([render, classProp]),
[]
)
path.remove()
return {
name: className,
ast: classDecl
}
} else if (is) {
const value = is.node.value
if (!value) {
throw new Error('template 的 `is` 属性不能为空')
}
if (t.isStringLiteral(value)) {
const className = buildTemplateName(value.value)
let attributes: t.JSXAttribute[] = []
if (data) {
attributes.push(data.node)
}
path.replaceWith(t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier(className), attributes),
t.jSXClosingElement(t.jSXIdentifier(className)),
[],
true
))
} else if (t.isJSXExpressionContainer(value)) {
if (t.isStringLiteral(value.expression)) {
const className = buildTemplateName(value.expression.value)
let attributes: t.JSXAttribute[] = []
if (data) {
attributes.push(data.node)
}
path.replaceWith(t.jSXElement(
t.jSXOpeningElement(t.jSXIdentifier(className), attributes),
t.jSXClosingElement(t.jSXIdentifier(className)),
[],
true
))
} else if (t.isConditional(value.expression)) {
const { test, consequent, alternate } = value.expression
if (!t.isStringLiteral(consequent) || !t.isStringLiteral(alternate)) {
throw new Error('当 template is 标签是三元表达式时,他的两个值都必须为字符串')
}
let attributes: t.JSXAttribute[] = []
if (data) {
attributes.push(data.node)
}
const block = buildBlockElement()
block.children = [t.jSXExpressionContainer(t.conditionalExpression(
//.........这里部分代码省略.........
开发者ID:YangShaoQun,项目名称:taro,代码行数:101,代码来源:template.ts
注:本文中的babel-types.jSXOpeningElement函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论