Skip to content

Commit cbd4d41

Browse files
kazuponyyx990803
authored andcommitted
feat(template-compiler): add compilerDirectives option (#977)
1 parent 2a0212c commit cbd4d41

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

lib/template-compiler/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = function (html) {
2323
var compilerOptions = {
2424
preserveWhitespace: options.preserveWhitespace,
2525
modules: defaultModules.concat(userModules || []),
26+
directives: vueOptions.compilerDirectives || options.compilerDirectives || {},
2627
scopeId: options.hasScoped ? options.id : null
2728
}
2829

test/fixtures/custom-directive.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<template>
2+
<p v-i18n="keypath"></p>
3+
</template>

test/test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,29 @@ describe('vue-loader', function () {
872872
})
873873
})
874874

875+
it('custom compiler directives', done => {
876+
test({
877+
entry: './test/fixtures/custom-directive.vue',
878+
vue: {
879+
compilerDirectives: {
880+
i18n (el, dir) {
881+
if (dir.name === 'i18n' && dir.value) {
882+
el.i18n = dir.value
883+
if (!el.props) {
884+
el.props = []
885+
}
886+
el.props.push({ name: 'textContent', value: `_s(${JSON.stringify(dir.value)})` })
887+
}
888+
}
889+
}
890+
}
891+
}, (window, module) => {
892+
var vnode = mockRender(module)
893+
expect(vnode.data.domProps.textContent).to.equal('keypath')
894+
done()
895+
})
896+
})
897+
875898
it('functional component with styles', done => {
876899
test({
877900
entry: './test/fixtures/functional-style.vue'

0 commit comments

Comments
 (0)