import { baseParse as parse, transform, CompilerOptions, generate } from '@vue/compiler-core' import { transformModel } from '../../src/transforms/vModel' import { transformElement } from '../../../compiler-core/src/transforms/transformElement' import { DOMErrorCodes } from '../../src/errors' import { V_MODEL_CHECKBOX, V_MODEL_DYNAMIC, V_MODEL_RADIO, V_MODEL_SELECT, V_MODEL_TEXT } from '../../src/runtimeHelpers' function transformWithModel(template: string, options: CompilerOptions = {}) { const ast = parse(template) transform(ast, { nodeTransforms: [transformElement], directiveTransforms: { model: transformModel }, ...options }) return ast } describe('compiler: transform v-model', () => { test('simple expression', () => { const root = transformWithModel('') expect(root.helpers).toContain(V_MODEL_TEXT) expect(generate(root).code).toMatchSnapshot() }) test('simple expression for input (text)', () => { const root = transformWithModel('') expect(root.helpers).toContain(V_MODEL_TEXT) expect(generate(root).code).toMatchSnapshot() }) test('simple expression for input (radio)', () => { const root = transformWithModel('') expect(root.helpers).toContain(V_MODEL_RADIO) expect(generate(root).code).toMatchSnapshot() }) test('simple expression for input (checkbox)', () => { const root = transformWithModel('') expect(root.helpers).toContain(V_MODEL_CHECKBOX) expect(generate(root).code).toMatchSnapshot() }) test('simple expression for input (dynamic type)', () => { const root = transformWithModel('') expect(root.helpers).toContain(V_MODEL_DYNAMIC) expect(generate(root).code).toMatchSnapshot() }) test('input w/ dynamic v-bind', () => { const root = transformWithModel('') expect(root.helpers).toContain(V_MODEL_DYNAMIC) expect(generate(root).code).toMatchSnapshot() const root2 = transformWithModel( '' ) expect(root2.helpers).toContain(V_MODEL_DYNAMIC) expect(generate(root2).code).toMatchSnapshot() }) test('simple expression for select', () => { const root = transformWithModel('