@vue/language-plugin-pug 3.0.7-alpha.1 → 3.0.8

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 (2) hide show
  1. package/index.js +54 -56
  2. 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?.baseParse(template);
45
+ pugFile = pug.baseParse(template);
46
46
  }
47
47
  else {
48
- pugFile = pug?.baseParse(`template\n${template}`);
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
- if (pugFile) {
55
- const map = new source_map_1.SourceMap(pugFile.mappings);
56
- const compiler = modules['@vue/compiler-dom'];
57
- const completed = compiler.compile(pugFile.htmlCode, {
58
- ...options,
59
- comments: true,
60
- onWarn(warning) {
61
- options?.onWarn?.(createProxyObject(warning));
62
- },
63
- onError(error) {
64
- // #5099
65
- if (error.code === 2
66
- && classRegex.test(pugFile.htmlCode.slice(error.loc?.start.offset))) {
67
- return;
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
- options?.onError?.(createProxyObject(error));
70
- },
71
- });
72
- return createProxyObject(completed);
73
- function createProxyObject(target) {
74
- const proxys = new WeakMap();
75
- return new Proxy(target, {
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
- return value;
101
- },
102
- });
103
- }
104
- function getOffset(offset) {
105
- const htmlOffset = offset;
106
- const nums = [];
107
- for (const mapped of map.toSourceLocation(htmlOffset)) {
108
- nums.push(mapped[0] - baseOffset);
109
- }
110
- return Math.max(-1, ...nums);
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-alpha.1",
3
+ "version": "3.0.8",
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-alpha.1"
22
+ "@vue/language-core": "3.0.8"
23
23
  },
24
- "gitHead": "320fc626c871e9ff17c0e4e92ea7ddb0c7641f34"
24
+ "gitHead": "f7bdeaa7bb476df1fc8ff46c504d75c1869b0be9"
25
25
  }