import { transformElement } from './transforms/transformElement'
import { transformVHtml } from './transforms/vHtml'
import { transformVText } from './transforms/vText'
+import { transformVBind } from './transforms/vBind'
import { transformVOn } from './transforms/vOn'
import { transformInterpolation } from './transforms/transformInterpolation'
import type { HackOptions } from './ir'
return [
[transformOnce, transformInterpolation, transformElement],
{
+ bind: transformVBind,
on: transformVOn,
html: transformVHtml,
text: transformVText,
type ElementNode,
type AttributeNode,
NodeTypes,
- ErrorCodes,
- createCompilerError,
ElementTypes,
- createSimpleExpression,
} from '@vue/compiler-dom'
-import { camelize, isBuiltInDirective, isVoidTag } from '@vue/shared'
+import { isBuiltInDirective, isVoidTag } from '@vue/shared'
import { NodeTransform, TransformContext } from '../transform'
import { VaporDirectiveNode, IRNodeTypes } from '../ir'
return
}
- let { arg, exp, loc } = prop
const directiveTransform = context.options.directiveTransforms[name]
if (directiveTransform) {
directiveTransform(prop, node, context)
} else if (!isBuiltInDirective(name)) {
+ // custom directive
context.registerOperation({
type: IRNodeTypes.WITH_DIRECTIVE,
element: context.reference(),
name,
- binding: exp,
+ binding: prop.exp,
loc: prop.loc,
})
}
-
- switch (name) {
- case 'bind': {
- if (!arg) {
- // TODO support v-bind="{}"
- return
- }
- if (!exp) {
- // shorthand syntax https://github.com/vuejs/core/pull/9451
- const propName = camelize(arg.content)
- exp = createSimpleExpression(propName, false, arg.loc)
- exp.ast = null
- }
-
- if (!exp.content.trim()) {
- context.options.onError(
- createCompilerError(ErrorCodes.X_V_BIND_NO_EXPRESSION, loc),
- )
- context.template += ` ${arg.content}=""`
- return
- }
-
- context.registerEffect(
- [exp],
- [
- {
- type: IRNodeTypes.SET_PROP,
- loc: prop.loc,
- element: context.reference(),
- name: arg,
- value: exp,
- },
- ],
- )
- break
- }
- }
}
--- /dev/null
+import {
+ createCompilerError,
+ createSimpleExpression,
+ ErrorCodes,
+} from '@vue/compiler-core'
+import { camelize } from '@vue/shared'
+import { IRNodeTypes } from '../ir'
+import type { DirectiveTransform } from '../transform'
+
+export const transformVBind: DirectiveTransform = (dir, node, context) => {
+ let { arg, exp, loc } = dir
+
+ if (!arg) {
+ // TODO support v-bind="{}"
+ return
+ }
+ if (!exp) {
+ // shorthand syntax https://github.com/vuejs/core/pull/9451
+ const propName = camelize(arg.content)
+ exp = createSimpleExpression(propName, false, arg.loc)
+ exp.ast = null
+ }
+
+ if (!exp.content.trim()) {
+ context.options.onError(
+ createCompilerError(ErrorCodes.X_V_BIND_NO_EXPRESSION, loc),
+ )
+ context.template += ` ${arg.content}=""`
+ return
+ }
+
+ context.registerEffect(
+ [exp],
+ [
+ {
+ type: IRNodeTypes.SET_PROP,
+ loc: dir.loc,
+ element: context.reference(),
+ name: arg,
+ value: exp,
+ },
+ ],
+ )
+}