Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getImportsExpressionExp(
path: string | undefined,
hash: string | undefined,
loc: SourceLocation,
context: TransformContext
): ExpressionNode {
if (path) {
const importsArray = Array.from(context.imports)
const existing = importsArray.find(i => i.path === path)
if (existing) {
return existing.exp as ExpressionNode
}
const name = `_imports_${importsArray.length}`
const exp = createSimpleExpression(name, false, loc, true)
context.imports.add({ exp, path })
if (hash && path) {
return context.hoist(
createSimpleExpression(`${name} + '${hash}'`, false, loc, true)
)
} else {
return exp
}
} else {
return createSimpleExpression(`''`, false, loc, true)
}
}
if (!exp) {
context.onError(
createDOMCompilerError(DOMErrorCodes.X_V_TEXT_NO_EXPRESSION, loc)
)
}
if (node.children.length) {
context.onError(
createDOMCompilerError(DOMErrorCodes.X_V_TEXT_WITH_CHILDREN, loc)
)
node.children.length = 0
}
return {
props: [
createObjectProperty(
createSimpleExpression(`textContent`, true, loc),
exp || createSimpleExpression('', true)
)
],
needRuntime: false
}
}
const existing = importsArray.find(i => i.path === path)
if (existing) {
return existing.exp as ExpressionNode
}
const name = `_imports_${importsArray.length}`
const exp = createSimpleExpression(name, false, loc, true)
context.imports.add({ exp, path })
if (hash && path) {
return context.hoist(
createSimpleExpression(`${name} + '${hash}'`, false, loc, true)
)
} else {
return exp
}
} else {
return createSimpleExpression(`''`, false, loc, true)
}
}
const { exp, loc } = dir
if (!exp) {
context.onError(
createDOMCompilerError(DOMErrorCodes.X_V_TEXT_NO_EXPRESSION, loc)
)
}
if (node.children.length) {
context.onError(
createDOMCompilerError(DOMErrorCodes.X_V_TEXT_WITH_CHILDREN, loc)
)
node.children.length = 0
}
return {
props: [
createObjectProperty(
createSimpleExpression(`textContent`, true, loc),
exp || createSimpleExpression('', true)
)
],
needRuntime: false
}
}
eventOptionModifiers.map(modifier =>
createObjectProperty(
modifier,
createSimpleExpression('true', false)
)
)
hash: string | undefined,
loc: SourceLocation,
context: TransformContext
): ExpressionNode {
if (path) {
const importsArray = Array.from(context.imports)
const existing = importsArray.find(i => i.path === path)
if (existing) {
return existing.exp as ExpressionNode
}
const name = `_imports_${importsArray.length}`
const exp = createSimpleExpression(name, false, loc, true)
context.imports.add({ exp, path })
if (hash && path) {
return context.hoist(
createSimpleExpression(`${name} + '${hash}'`, false, loc, true)
)
} else {
return exp
}
} else {
return createSimpleExpression(`''`, false, loc, true)
}
}
const { exp, loc } = dir
if (!exp) {
context.onError(
createDOMCompilerError(DOMErrorCodes.X_V_HTML_NO_EXPRESSION, loc)
)
}
if (node.children.length) {
context.onError(
createDOMCompilerError(DOMErrorCodes.X_V_HTML_WITH_CHILDREN, loc)
)
node.children.length = 0
}
return {
props: [
createObjectProperty(
createSimpleExpression(`innerHTML`, true, loc),
exp || createSimpleExpression('', true)
)
],
needRuntime: false
}
}
compoundExpression.children.push(exp)
}
const isNotLast = imageCandidates.length - 1 > index
if (descriptor && isNotLast) {
compoundExpression.children.push(` + '${descriptor}, ' + `)
} else if (descriptor) {
compoundExpression.children.push(` + '${descriptor}'`)
} else if (isNotLast) {
compoundExpression.children.push(` + ', ' + `)
}
})
node.props[index] = {
type: NodeTypes.DIRECTIVE,
name: 'bind',
arg: createSimpleExpression('srcset', true, attr.loc),
exp: context.hoist(compoundExpression),
modifiers: [],
loc: attr.loc
}
}
})
}