vBind.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.transformBind = void 0;
  4. const shared_1 = require("@vue/shared");
  5. const compiler_core_1 = require("@vue/compiler-core");
  6. const errors_1 = require("../errors");
  7. const transformBind = (dir, _node, context) => {
  8. const { exp, modifiers, loc } = dir;
  9. const arg = dir.arg;
  10. if (arg.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  11. arg.children.unshift(`(`);
  12. arg.children.push(`) || ""`);
  13. }
  14. else if (!arg.isStatic) {
  15. arg.content = `${arg.content} || ""`;
  16. }
  17. // .sync is replaced by v-model:arg
  18. if (modifiers.includes('camel')) {
  19. if (arg.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
  20. if (arg.isStatic) {
  21. arg.content = (0, shared_1.camelize)(arg.content);
  22. }
  23. else {
  24. // arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`
  25. }
  26. }
  27. else {
  28. // arg.children.unshift(`${context.helperString(CAMELIZE)}(`)
  29. // arg.children.push(`)`)
  30. }
  31. }
  32. if (modifiers.includes('prop')) {
  33. context.onWarn((0, errors_1.createMPCompilerError)(4 /* MPErrorCodes.X_V_BIND_MODIFIER_PROP */, loc));
  34. }
  35. if (modifiers.includes('attr')) {
  36. context.onWarn((0, errors_1.createMPCompilerError)(5 /* MPErrorCodes.X_V_BIND_MODIFIER_ATTR */, loc));
  37. }
  38. if (!exp ||
  39. (exp.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !exp.content.trim())) {
  40. context.onError((0, compiler_core_1.createCompilerError)(34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */, loc));
  41. return {
  42. props: [(0, compiler_core_1.createObjectProperty)(arg, (0, compiler_core_1.createSimpleExpression)('', true, loc))],
  43. };
  44. }
  45. return {
  46. props: [(0, compiler_core_1.createObjectProperty)(arg, exp)],
  47. };
  48. };
  49. exports.transformBind = transformBind;