@vue/language-plugin-pug 2.0.0 → 2.0.1

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.
Files changed (3) hide show
  1. package/index.d.ts +3 -0
  2. package/index.js +49 -0
  3. package/package.json +5 -5
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { VueLanguagePlugin } from '@vue/language-core';
2
+ declare const plugin: VueLanguagePlugin;
3
+ export = plugin;
package/index.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ const pug = require("volar-service-pug/lib/languageService");
3
+ const source_map_1 = require("@volar/source-map");
4
+ const plugin = ({ modules }) => {
5
+ return {
6
+ name: require('../package.json').name,
7
+ version: 2,
8
+ compileSFCTemplate(lang, template, options) {
9
+ if (lang === 'pug') {
10
+ const pugFile = pug?.baseParse(template);
11
+ const map = new source_map_1.SourceMap(pugFile.mappings);
12
+ if (pugFile) {
13
+ const compiler = modules['@vue/compiler-dom'];
14
+ const completed = compiler.compile(pugFile.htmlCode, {
15
+ ...options,
16
+ comments: true,
17
+ onWarn(warning) {
18
+ options?.onWarn?.(createProxyObject(warning));
19
+ },
20
+ onError(error) {
21
+ options?.onError?.(createProxyObject(error));
22
+ },
23
+ });
24
+ return createProxyObject(completed);
25
+ function createProxyObject(target) {
26
+ return new Proxy(target, {
27
+ get(target, prop) {
28
+ if (prop === 'offset') {
29
+ const htmlOffset = target.offset;
30
+ for (const mapped of map.getSourceOffsets(htmlOffset)) {
31
+ return mapped[0];
32
+ }
33
+ return -1;
34
+ }
35
+ const value = target[prop];
36
+ if (typeof value === 'object') {
37
+ return createProxyObject(target[prop]);
38
+ }
39
+ return value;
40
+ }
41
+ });
42
+ }
43
+ }
44
+ }
45
+ },
46
+ };
47
+ };
48
+ module.exports = plugin;
49
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@vue/language-plugin-pug",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "license": "MIT",
5
5
  "files": [
6
- "out/**/*.js",
7
- "out/**/*.d.ts"
6
+ "**/*.js",
7
+ "**/*.d.ts"
8
8
  ],
9
9
  "repository": {
10
10
  "type": "git",
@@ -13,11 +13,11 @@
13
13
  },
14
14
  "devDependencies": {
15
15
  "@types/node": "latest",
16
- "@vue/language-core": "2.0.0"
16
+ "@vue/language-core": "2.0.1"
17
17
  },
18
18
  "dependencies": {
19
19
  "@volar/source-map": "~2.1.0",
20
20
  "volar-service-pug": "0.0.31"
21
21
  },
22
- "gitHead": "aa47e5a7d8a6dae62cc80dbdb5db6a9bfa4f8715"
22
+ "gitHead": "adedfd0983c910370d080e955702cca7d2275420"
23
23
  }