Skip to content

Commit 2b3ed31

Browse files
committed
be able to parse the recyclable flag on <template>
1 parent 73d34ec commit 2b3ed31

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/loader.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ var checkNamedExports =
4646
'if (Object.keys(__vue_exports__).some(function (key) { return key !== "default" && key !== "__esModule" })) {' +
4747
'console.error("named exports are not supported in *.vue files.")}\n'
4848

49+
function hasRecyclable (template) {
50+
return !!(template && template.attrs && template.attrs.recyclable)
51+
}
52+
4953
module.exports = function (content) {
5054
this.cacheable()
5155
// var isServer = this.options.target === 'node'
@@ -159,6 +163,9 @@ module.exports = function (content) {
159163
if (type === 'styles') {
160164
loader = addCssModulesToLoader(loader, part, index)
161165
}
166+
if (type === 'template' && hasRecyclable(part)) {
167+
loader += '&recyclable=true'
168+
}
162169
// inject rewriter before css/html loader for
163170
// extractTextPlugin use cases
164171
if (rewriterInjectRE.test(loader)) {
@@ -302,6 +309,7 @@ module.exports = function (content) {
302309
// attach render functions to exported options
303310
exports +=
304311
'__vue_options__.render = __vue_template__.render\n' +
312+
(hasRecyclable(template) ? '__vue_options__["@render"] = __vue_template__["@render"]\n' : '') +
305313
'__vue_options__.staticRenderFns = __vue_template__.staticRenderFns\n'
306314
}
307315

lib/template-compiler.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var compiler = require('weex-template-compiler')
88
var transpile = require('vue-template-es2015-compiler')
9-
// var loaderUtils = require('loader-utils')
9+
var loaderUtils = require('loader-utils')
1010
var beautify = require('js-beautify').js_beautify
1111
// var normalize = require('./normalize')
1212
// var hotReloadAPIPath = normalize.dep('vue-hot-reload-api')
@@ -54,7 +54,7 @@ var beautify = require('js-beautify').js_beautify
5454
module.exports = function (html) {
5555
this.cacheable()
5656
var isProduction = this.minimize || process.env.NODE_ENV === 'production'
57-
// var query = loaderUtils.parseQuery(this.query)
57+
var query = loaderUtils.parseQuery(this.query)
5858
// var isServer = this.options.target === 'node'
5959
// var isServer = false
6060
var vueOptions = this.options.__vueOptions__
@@ -68,7 +68,9 @@ module.exports = function (html) {
6868
// var compiled = compiler.compile(html, Object.assign({
6969
// preserveWhitespace: vueOptions.preserveWhitespace
7070
// }, defaultCompileOptions))
71-
var compiled = compiler.compile(html)
71+
var compiled = compiler.compile(html, {
72+
recyclable: query.recyclable
73+
})
7274
var code
7375
if (compiled.errors.length) {
7476
var self = this
@@ -80,6 +82,7 @@ module.exports = function (html) {
8082
var bubleOptions = vueOptions.buble
8183
code = transpile('module.exports={' +
8284
'render:' + toFunction(compiled.render) + ',' +
85+
(compiled['@render'] ? ('"@render":' + toFunction(compiled['@render']) + ',') : '') +
8386
'staticRenderFns: [' + compiled.staticRenderFns.map(toFunction).join(',') + ']' +
8487
'}', bubleOptions)
8588
// mark with stripped (this enables Vue to use correct runtime proxy detection)

0 commit comments

Comments
 (0)