From c40b6a928959a865119ccc69520870c147f48e84 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 15 Sep 2017 01:41:22 +0900 Subject: [PATCH] feat(template-compiler): add compilerDirectives option --- lib/template-compiler/index.js | 1 + test/fixtures/custom-directive.vue | 3 +++ test/test.js | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 test/fixtures/custom-directive.vue diff --git a/lib/template-compiler/index.js b/lib/template-compiler/index.js index d868bbb44..53bcb4fcc 100644 --- a/lib/template-compiler/index.js +++ b/lib/template-compiler/index.js @@ -23,6 +23,7 @@ module.exports = function (html) { var compilerOptions = { preserveWhitespace: options.preserveWhitespace, modules: defaultModules.concat(userModules || []), + directives: vueOptions.compilerDirectives || options.compilerDirectives || {}, scopeId: options.hasScoped ? options.id : null } diff --git a/test/fixtures/custom-directive.vue b/test/fixtures/custom-directive.vue new file mode 100644 index 000000000..b11d74e33 --- /dev/null +++ b/test/fixtures/custom-directive.vue @@ -0,0 +1,3 @@ + diff --git a/test/test.js b/test/test.js index 369b69906..c972f774a 100644 --- a/test/test.js +++ b/test/test.js @@ -872,6 +872,29 @@ describe('vue-loader', function () { }) }) + it('custom compiler directives', done => { + test({ + entry: './test/fixtures/custom-directive.vue', + vue: { + compilerDirectives: { + i18n (el, dir) { + if (dir.name === 'i18n' && dir.value) { + el.i18n = dir.value + if (!el.props) { + el.props = [] + } + el.props.push({ name: 'textContent', value: `_s(${JSON.stringify(dir.value)})` }) + } + } + } + } + }, (window, module) => { + var vnode = mockRender(module) + expect(vnode.data.domProps.textContent).to.equal('keypath') + done() + }) + }) + it('functional component with styles', done => { test({ entry: './test/fixtures/functional-style.vue'