/**
* Separate option for end users to extend the native elements list
*/
- isCustomElement?: (tag: string) => boolean
+ isCustomElement?: (tag: string) => boolean | void
/**
* Get tag namespace
*/
* for them.
*/
isBuiltInComponent?: (tag: string) => symbol | void
+ /**
+ * Used by some transforms that expects only native elements
+ */
+ isCustomElement?: (tag: string) => boolean | void
/**
* Transform expressions like {{ foo }} to `_ctx.foo`.
* If this option is false, the generated code will be wrapped in a
directiveTransforms = {},
transformHoist = null,
isBuiltInComponent = NOOP,
+ isCustomElement = NOOP,
expressionPlugins = [],
scopeId = null,
ssr = false,
directiveTransforms,
transformHoist,
isBuiltInComponent,
+ isCustomElement,
expressionPlugins,
scopeId,
ssr,
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`compiler: transform v-model errors should allow custom element 1`] = `
+"const _Vue = Vue
+
+return function render(_ctx, _cache) {
+ with (_ctx) {
+ const { vModelText: _vModelText, createVNode: _createVNode, withDirectives: _withDirectives, openBlock: _openBlock, createBlock: _createBlock } = _Vue
+
+ return _withDirectives((_openBlock(), _createBlock(\\"my-input\\", {
+ \\"onUpdate:modelValue\\": $event => (model = $event)
+ }, null, 8 /* PROPS */, [\\"onUpdate:modelValue\\"])), [
+ [_vModelText, model]
+ ])
+ }
+}"
+`;
+
exports[`compiler: transform v-model input w/ dynamic v-bind 1`] = `
"const _Vue = Vue
)
})
+ test('should allow usage on custom element', () => {
+ const onError = jest.fn()
+ const root = transformWithModel('<my-input v-model="model" />', {
+ onError,
+ isCustomElement: tag => tag.startsWith('my-')
+ })
+ expect(root.helpers).toContain(V_MODEL_TEXT)
+ expect(onError).not.toHaveBeenCalled()
+ expect(generate(root).code).toMatchSnapshot()
+ })
+
test('should raise error if used file input element', () => {
const onError = jest.fn()
transformWithModel(`<input type="file" v-model="test"/>`, {
}
const { tag } = node
- if (tag === 'input' || tag === 'textarea' || tag === 'select') {
+ if (
+ tag === 'input' ||
+ tag === 'textarea' ||
+ tag === 'select' ||
+ context.isCustomElement(tag)
+ ) {
let directiveToUse = V_MODEL_TEXT
let isInvalidType = false
if (tag === 'input') {
}
} else if (tag === 'select') {
directiveToUse = V_MODEL_SELECT
- } else if (tag === 'textarea') {
+ }
+ {
+ // textarea or custom elements
__DEV__ && checkDuplicatedValue()
}
// inject runtime directive