From 4f549b566741dd69d8eaabeee78d771861663375 Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Sun, 29 Jan 2017 15:58:17 +0530 Subject: [PATCH] :bug: Supress warning when compiling template --- src/vueTransform.js | 17 +++++++++-------- test/expects/slot.js | 2 +- test/expects/table-n-slot.js | 3 +++ test/expects/table.js | 2 +- test/fixtures/table-n-slot.vue | 11 +++++++++++ test/fixtures/table.vue | 2 +- test/test.js | 7 +++---- 7 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 test/expects/table-n-slot.js create mode 100644 test/fixtures/table-n-slot.vue diff --git a/src/vueTransform.js b/src/vueTransform.js index 6760297..9b34639 100644 --- a/src/vueTransform.js +++ b/src/vueTransform.js @@ -95,22 +95,23 @@ function injectTemplate (script, template, lang, options) { function processTemplate (source, id, content, options) { if (source === undefined) return undefined - const {node, code} = source + const { code } = source + const template = deIndent(code) + const ignore = [ + 'Found camelCase attribute:', + 'Tag cannot appear inside due to HTML content restrictions.' + ] const warnings = validateTemplate(code, content) if (warnings) { const relativePath = relative(process.cwd(), id) - warnings.forEach((msg) => { + warnings.filter((warning) => { + return options.compileTemplate && ignore.findIndex(i => warning.indexOf(i) > -1) < 0 + }).forEach((msg) => { console.warn(`\n Warning in ${relativePath}:\n ${msg}`) }) } - /* eslint-disable no-underscore-dangle */ - const start = node.content.childNodes[0].__location.startOffset - const end = node.content.childNodes[node.content.childNodes.length - 1].__location.endOffset - const template = deIndent(content.slice(start, end)) - /* eslint-enable no-underscore-dangle */ - return htmlMinifier.minify(template, options.htmlMinifier) } diff --git a/test/expects/slot.js b/test/expects/slot.js index 3df3bf1..011c321 100644 --- a/test/expects/slot.js +++ b/test/expects/slot.js @@ -1,4 +1,4 @@ -var TableComponent = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('table',[_c('tr',[_c('td',[_vm._t("default",[_vm._t("default")])],2)])])},staticRenderFns: [],}; +var TableComponent = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('table',[_c('tr',[_c('td',[_vm._t("default")],2)])])},staticRenderFns: [],}; var slot = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('table-component',[_vm._v("Hello! World")])},staticRenderFns: [], components: { TableComponent }, diff --git a/test/expects/table-n-slot.js b/test/expects/table-n-slot.js new file mode 100644 index 0000000..0c281ec --- /dev/null +++ b/test/expects/table-n-slot.js @@ -0,0 +1,3 @@ +var tableNSlot = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('table',[_c('tbody',[_vm._t("default")],2)])},staticRenderFns: [],}; + +export default tableNSlot; diff --git a/test/expects/table.js b/test/expects/table.js index 9e88530..e1693ff 100644 --- a/test/expects/table.js +++ b/test/expects/table.js @@ -1,3 +1,3 @@ -var table = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('table',[_c('tr',[_c('td',[_vm._t("default",[_vm._t("default")])],2)])])},staticRenderFns: [],}; +var table = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('table',[_c('tr',[_c('td',[_vm._t("default")],2)])])},staticRenderFns: [],}; export default table; diff --git a/test/fixtures/table-n-slot.vue b/test/fixtures/table-n-slot.vue new file mode 100644 index 0000000..a1e284c --- /dev/null +++ b/test/fixtures/table-n-slot.vue @@ -0,0 +1,11 @@ + + + diff --git a/test/fixtures/table.vue b/test/fixtures/table.vue index 24221dc..9492eea 100644 --- a/test/fixtures/table.vue +++ b/test/fixtures/table.vue @@ -2,7 +2,7 @@
- +
diff --git a/test/test.js b/test/test.js index 44d6044..3ad19cc 100644 --- a/test/test.js +++ b/test/test.js @@ -23,14 +23,13 @@ function test(name) { } return rollup.rollup({ - format: 'cjs', entry: entry, plugins: [vuePlugin({ css: cssHandler, - compileTemplate: ['compileTemplate', 'slot', 'table'].indexOf(name) > -1 + compileTemplate: ['compileTemplate', 'slot', 'table', 'table-n-slot'].indexOf(name) > -1 })] }).then(function (bundle) { - var result = bundle.generate() + var result = bundle.generate({format: 'es'}) var code = result.code assert.equal(code.trim(), expected.trim(), 'should compile code correctly') @@ -74,7 +73,7 @@ describe('styleToImports', function () { }), ], }).then(function (bundle) { - bundle.generate() + bundle.generate({ format: 'es' }) assert.equal(expectedCss.trim(), actualCss.trim(), 'should import style') }).catch(function (error) {