@vue/language-plugin-pug 3.0.7-alpha.0 → 3.0.7
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 +54 -56
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -42,73 +42,71 @@ const plugin = ({ modules }) => {
|
|
|
42
42
|
let baseOffset = 0;
|
|
43
43
|
const minIndent = calculateMinIndent(template);
|
|
44
44
|
if (minIndent === 0) {
|
|
45
|
-
pugFile = pug
|
|
45
|
+
pugFile = pug.baseParse(template);
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
48
|
-
pugFile = pug
|
|
48
|
+
pugFile = pug.baseParse(`template\n${template}`);
|
|
49
49
|
baseOffset = 'template\n'.length;
|
|
50
50
|
pugFile.htmlCode = ' '.repeat('<template>'.length)
|
|
51
51
|
+ pugFile.htmlCode.slice('<template>'.length, -'</template>'.length)
|
|
52
52
|
+ ' '.repeat('</template>'.length);
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
onWarn(warning)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
const map = new source_map_1.SourceMap(pugFile.mappings);
|
|
55
|
+
const compiler = modules['@vue/compiler-dom'];
|
|
56
|
+
const completed = compiler.compile(pugFile.htmlCode, {
|
|
57
|
+
...options,
|
|
58
|
+
comments: true,
|
|
59
|
+
onWarn(warning) {
|
|
60
|
+
options.onWarn?.(createProxyObject(warning));
|
|
61
|
+
},
|
|
62
|
+
onError(error) {
|
|
63
|
+
// #5099
|
|
64
|
+
if (error.code === 2
|
|
65
|
+
&& classRegex.test(pugFile.htmlCode.slice(error.loc?.start.offset))) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
options.onError?.(createProxyObject(error));
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return createProxyObject(completed);
|
|
72
|
+
function createProxyObject(target) {
|
|
73
|
+
const proxys = new WeakMap();
|
|
74
|
+
return new Proxy(target, {
|
|
75
|
+
get(target, prop, receiver) {
|
|
76
|
+
if (prop === 'getClassOffset') {
|
|
77
|
+
// div.foo#baz.bar
|
|
78
|
+
// ^^^ ^^^
|
|
79
|
+
// class=" foo bar"
|
|
80
|
+
// ^^^ ^^^
|
|
81
|
+
// NOTE: we need to expose source offset getter
|
|
82
|
+
return function (startOffset) {
|
|
83
|
+
return getOffset(target.offset + startOffset);
|
|
84
|
+
};
|
|
68
85
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
get(target, prop, receiver) {
|
|
77
|
-
if (prop === 'getClassOffset') {
|
|
78
|
-
// div.foo#baz.bar
|
|
79
|
-
// ^^^ ^^^
|
|
80
|
-
// class=" foo bar"
|
|
81
|
-
// ^^^ ^^^
|
|
82
|
-
// NOTE: we need to expose source offset getter
|
|
83
|
-
return function (startOffset) {
|
|
84
|
-
return getOffset(target.offset + startOffset);
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if (prop === 'offset') {
|
|
88
|
-
return getOffset(target.offset);
|
|
89
|
-
}
|
|
90
|
-
const value = Reflect.get(target, prop, receiver);
|
|
91
|
-
if (typeof value === 'object' && value !== null) {
|
|
92
|
-
let proxyed = proxys.get(value);
|
|
93
|
-
if (proxyed) {
|
|
94
|
-
return proxyed;
|
|
95
|
-
}
|
|
96
|
-
proxyed = createProxyObject(value);
|
|
97
|
-
proxys.set(value, proxyed);
|
|
86
|
+
if (prop === 'offset') {
|
|
87
|
+
return getOffset(target.offset);
|
|
88
|
+
}
|
|
89
|
+
const value = Reflect.get(target, prop, receiver);
|
|
90
|
+
if (typeof value === 'object' && value !== null) {
|
|
91
|
+
let proxyed = proxys.get(value);
|
|
92
|
+
if (proxyed) {
|
|
98
93
|
return proxyed;
|
|
99
94
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
proxyed = createProxyObject(value);
|
|
96
|
+
proxys.set(value, proxyed);
|
|
97
|
+
return proxyed;
|
|
98
|
+
}
|
|
99
|
+
return value;
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function getOffset(offset) {
|
|
104
|
+
const htmlOffset = offset;
|
|
105
|
+
const nums = [];
|
|
106
|
+
for (const mapped of map.toSourceLocation(htmlOffset)) {
|
|
107
|
+
nums.push(mapped[0] - baseOffset);
|
|
111
108
|
}
|
|
109
|
+
return Math.max(-1, ...nums);
|
|
112
110
|
}
|
|
113
111
|
}
|
|
114
112
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/language-plugin-pug",
|
|
3
|
-
"version": "3.0.7
|
|
3
|
+
"version": "3.0.7",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@types/node": "^22.10.4",
|
|
21
21
|
"@vue/compiler-dom": "^3.5.0",
|
|
22
|
-
"@vue/language-core": "3.0.7
|
|
22
|
+
"@vue/language-core": "3.0.7"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "6022b75534487f8a031dfc61a7879f900b64d414"
|
|
25
25
|
}
|