-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-vue-template-compiler-wrapper.js
47 lines (45 loc) · 1.86 KB
/
create-vue-template-compiler-wrapper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const VueTemplateCompiler = require('vue-template-compiler')
const { attrsToQuery } = require('vue-loader/lib/codegen/utils')
const extractTagsFromAst = require('./extract-tags-from-ast')
const tagsCache = require('./tags-cache')
module.exports = function createVueTemplateCompilerWrapper (compiler) {
const innerCompiler = compiler || VueTemplateCompiler
return {
...innerCompiler,
parseComponent (source, options) {
const descriptor = innerCompiler.parseComponent(source, options)
if (descriptor.template != null) {
// see https://github.com/vuejs/vue-loader/blob/master/lib/index.js#L94
// const idQuery = `&id=${id}` // TODO generate idQuery
const hasScoped = descriptor.styles.some(s => s.scoped)
descriptor.customBlocks.push({
type: 'auto-import-tags',
content: '', // TODO generate idQuery , cause we cannot get id here, we must pass source to where id can be calucated
attrs: {
idQuery: '', // TODO generate idQuery
scopedQuery: hasScoped ? `&scoped=true` : ``,
attrsQuery: attrsToQuery(descriptor.template.attrs),
inheritQuery: `&` // TODO should be `&${rawQuery}`
}
})
}
return descriptor
},
compile (template, options) {
//console.log('auto-import-tags compile ' + options.filename)
const compiled = innerCompiler.compile(template, options)
if (compiled.ast != null) {
tagsCache.set(options.filename, extractTagsFromAst(compiled.ast))
}
return compiled
},
ssrCompile (template, options) {
//console.log('auto-import-tags ssrCompile ' + options.filename)
const compiled = innerCompiler.ssrCompile(template, options)
if (compiled.ast != null) {
tagsCache.set(options.filename, extractTagsFromAst(compiled.ast))
}
return compiled
}
}
}