@vue/language-plugin-pug 2.1.4 → 2.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +56 -3
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -5,11 +5,53 @@ const plugin = ({ modules }) => {
|
|
|
5
5
|
return {
|
|
6
6
|
name: require('./package.json').name,
|
|
7
7
|
version: 2.1,
|
|
8
|
+
getEmbeddedCodes(_fileName, sfc) {
|
|
9
|
+
if (sfc.template?.lang === 'pug') {
|
|
10
|
+
return [{
|
|
11
|
+
id: 'template',
|
|
12
|
+
lang: sfc.template.lang,
|
|
13
|
+
}];
|
|
14
|
+
}
|
|
15
|
+
return [];
|
|
16
|
+
},
|
|
17
|
+
resolveEmbeddedCode(_fileName, sfc, embeddedFile) {
|
|
18
|
+
if (embeddedFile.id === 'template' && sfc.template?.lang === 'pug') {
|
|
19
|
+
const minIndent = calculateMinIndent(sfc.template.content);
|
|
20
|
+
if (minIndent !== 0) {
|
|
21
|
+
embeddedFile.content.push(`template\n`);
|
|
22
|
+
}
|
|
23
|
+
embeddedFile.content.push([
|
|
24
|
+
sfc.template.content,
|
|
25
|
+
sfc.template.name,
|
|
26
|
+
0,
|
|
27
|
+
{
|
|
28
|
+
verification: true,
|
|
29
|
+
completion: true,
|
|
30
|
+
semantic: true,
|
|
31
|
+
navigation: true,
|
|
32
|
+
structure: true,
|
|
33
|
+
format: true,
|
|
34
|
+
},
|
|
35
|
+
]);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
8
38
|
compileSFCTemplate(lang, template, options) {
|
|
9
39
|
if (lang === 'pug') {
|
|
10
|
-
|
|
11
|
-
|
|
40
|
+
let pugFile;
|
|
41
|
+
let baseOffset = 0;
|
|
42
|
+
const minIndent = calculateMinIndent(template);
|
|
43
|
+
if (minIndent === 0) {
|
|
44
|
+
pugFile = pug?.baseParse(template);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
pugFile = pug?.baseParse(`template\n${template}`);
|
|
48
|
+
baseOffset = 'template\n'.length;
|
|
49
|
+
pugFile.htmlCode = ' '.repeat('<template>'.length)
|
|
50
|
+
+ pugFile.htmlCode.slice('<template>'.length, -'</template>'.length)
|
|
51
|
+
+ ' '.repeat('</template>'.length);
|
|
52
|
+
}
|
|
12
53
|
if (pugFile) {
|
|
54
|
+
const map = new source_map_1.SourceMap(pugFile.mappings);
|
|
13
55
|
const compiler = modules['@vue/compiler-dom'];
|
|
14
56
|
const completed = compiler.compile(pugFile.htmlCode, {
|
|
15
57
|
...options,
|
|
@@ -57,7 +99,7 @@ const plugin = ({ modules }) => {
|
|
|
57
99
|
const htmlOffset = offset;
|
|
58
100
|
const nums = [];
|
|
59
101
|
for (const mapped of map.toSourceLocation(htmlOffset)) {
|
|
60
|
-
nums.push(mapped[0]);
|
|
102
|
+
nums.push(mapped[0] - baseOffset);
|
|
61
103
|
}
|
|
62
104
|
return Math.max(-1, ...nums);
|
|
63
105
|
}
|
|
@@ -66,5 +108,16 @@ const plugin = ({ modules }) => {
|
|
|
66
108
|
},
|
|
67
109
|
};
|
|
68
110
|
};
|
|
111
|
+
function calculateMinIndent(s) {
|
|
112
|
+
const lines = s.split('\n');
|
|
113
|
+
const minIndent = lines.reduce(function (minIndent, line) {
|
|
114
|
+
if (line.trim() === '') {
|
|
115
|
+
return minIndent;
|
|
116
|
+
}
|
|
117
|
+
const indent = line.match(/^\s*/)?.[0]?.length || 0;
|
|
118
|
+
return Math.min(indent, minIndent);
|
|
119
|
+
}, Infinity);
|
|
120
|
+
return minIndent;
|
|
121
|
+
}
|
|
69
122
|
module.exports = plugin;
|
|
70
123
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-plugin-pug",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"@types/node": "latest",
|
|
16
|
-
"@vue/language-core": "2.1.
|
|
16
|
+
"@vue/language-core": "2.1.6"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@volar/source-map": "~2.4.1",
|
|
20
20
|
"volar-service-pug": "0.0.62"
|
|
21
21
|
},
|
|
22
|
-
"gitHead": "
|
|
22
|
+
"gitHead": "fd61953ce9eb924eeaf4df0bf8d2237267321194"
|
|
23
23
|
}
|