/
configExtraContent.ts
53 lines (45 loc) · 1.59 KB
/
configExtraContent.ts
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
48
49
50
51
52
53
if (!module.exports.default)
module.exports.default = {};
if (!module.exports.default.vue)
module.exports.default.vue = {};
if (!module.exports.default.vue.compilerOptions)
module.exports.default.vue.compilerOptions = {};
if (!module.exports.default.vue.compilerOptions.nodeTransforms)
module.exports.default.vue.compilerOptions.nodeTransforms = [];
module.exports.default.vue.compilerOptions.nodeTransforms.push(
(node, ctx) => {
if (node.type === 1) {
const start = node.loc.start.offset;
const end = node.loc.end.offset;
addEvent(node, 'pointerenter', `$volar.highlight($event.target, $.type.__file, [${start},${end}])`);
addEvent(node, 'pointerleave', '$volar.unHighlight($event.target)');
addEvent(node, 'vnode-mounted', `$volar.vnodeMounted($event.el, $.type.__file, [${start},${end}])`);
addEvent(node, 'vnode-unmounted', '$volar.vnodeUnmounted($event.el)');
}
}
);
if (!module.exports.default.plugins)
module.exports.default.plugins = [];
module.exports.default.plugins.push({ src: '{PLUGIN_PATH}', ssr: false });
function addEvent(node, name: string, exp: string) {
node.props.push({
type: 7,
name: 'on',
exp: {
type: 4,
content: exp,
isStatic: false,
constType: 0,
loc: node.loc,
},
arg: {
type: 4,
content: name,
isStatic: true,
constType: 3,
loc: node.loc,
},
modifiers: [],
loc: node.loc,
});
}