Skip to content
Permalink
Browse files
support comment option in template (#897)
* support comment option in template

* Update loader.js

* Update template-comment.vue
  • Loading branch information
Kingwl authored and yyx990803 committed Jul 29, 2017
1 parent 7253e32 commit e6abc198c950345c4cf2e25f343025954412e907
Showing with 45 additions and 1 deletion.
  1. +2 −0 lib/loader.js
  2. +2 −1 lib/template-compiler/index.js
  3. +16 −0 test/fixtures/template-comment.vue
  4. +25 −0 test/test.js
@@ -89,10 +89,12 @@ module.exports = function (content) {
var output = ''
var parts = parse(content, fileName, this.sourceMap)
var hasScoped = parts.styles.some(function (s) { return s.scoped })
var hasComment = parts.template && parts.template.attrs.comments

This comment has been minimized.

Copy link
@ccforward

ccforward Aug 4, 2017

This line will report an error.
image

This comment has been minimized.

Copy link
@yyx990803

yyx990803 Aug 4, 2017

Member

Can you open a separate issue for this?


var templateCompilerOptions = '?' + JSON.stringify({
id: moduleId,
hasScoped: hasScoped,
hasComment: hasComment,
transformToRequire: options.transformToRequire,
preserveWhitespace: options.preserveWhitespace,
buble: options.buble,
@@ -23,7 +23,8 @@ module.exports = function (html) {
var compilerOptions = {
preserveWhitespace: options.preserveWhitespace,
modules: defaultModules.concat(userModules || []),
scopeId: options.hasScoped ? options.id : null
scopeId: options.hasScoped ? options.id : null,
comments: options.hasComment
}

var compile = isServer && compiler.ssrCompile && vueOptions.optimizeSSR !== false
@@ -0,0 +1,16 @@
<template comments>
<div>
<h2 class="red">{{msg}}</h2><!-- comment here -->
</div>
</template>

<script>
export default {
comments: true,
data () {
return {
msg: 'Hello from Component A!'
}
}
}
</script>
@@ -98,11 +98,18 @@ function mockRender (options, data) {
children: children
}
}
function e (text = '') {
return {
text: text,
isComment: true
}
}
return options.render.call(Object.assign({
_v (val) {
return val
},
_self: {},
_e: e,
$createElement: h,
_m (index) {
return options.staticRenderFns[index].call(this)
@@ -907,4 +914,22 @@ describe('vue-loader', function () {
done()
})
})

it('template with comments', done => {
test({
entry: './test/fixtures/template-comment.vue'
}, (window, module, rawModule) => {
expect(module.comments).to.equal(true)
var vnode = mockRender(module, {
msg: 'hi'
})
expect(vnode.tag).to.equal('div')
expect(vnode.children.length).to.equal(2)
expect(vnode.children[0].data.staticClass).to.equal('red')
expect(vnode.children[0].children[0]).to.equal('hi')
expect(vnode.children[1].isComment).to.true
expect(vnode.children[1].text).to.equal(' comment here ')
done()
})
})
})

0 comments on commit e6abc19

Please sign in to comment.