@vue/language-plugin-pug 3.2.4 → 3.2.5

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/README.md CHANGED
@@ -1,17 +1,70 @@
1
- A `VueLanguagePlugin` to support `<template lang="pug">` for `@vue/language-server`.
1
+ # @vue/language-plugin-pug
2
+
3
+ <p>
4
+ <a href="https://www.npmjs.com/package/@vue/language-plugin-pug"><img src="https://img.shields.io/npm/v/@vue/language-plugin-pug.svg?labelColor=18181B&color=1584FC" alt="NPM version"></a>
5
+ <a href="https://github.com/vuejs/language-tools/blob/master/LICENSE"><img src="https://img.shields.io/github/license/vuejs/language-tools.svg?labelColor=18181B&color=1584FC" alt="License"></a>
6
+ </p>
7
+
8
+ A Pug template language plugin for Vue Language Tools, enabling the use of `<template lang="pug">` in Vue SFCs.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @vue/language-plugin-pug --save-dev
14
+ ```
15
+
16
+ ## Configuration
17
+
18
+ Add this plugin in `tsconfig.json`:
19
+
20
+ ```jsonc
21
+ {
22
+ "vueCompilerOptions": {
23
+ "plugins": ["@vue/language-plugin-pug"]
24
+ }
25
+ }
26
+ ```
2
27
 
3
28
  ## Usage
4
29
 
5
- 1. Install
30
+ After configuration, you can use Pug syntax in Vue components:
31
+
32
+ ```vue
33
+ <template lang="pug">
34
+ div.container
35
+ h1 {{ title }}
36
+ p {{ description }}
37
+ button(@click="handleClick") Click me
38
+ </template>
39
+
40
+ <script setup lang="ts">
41
+ const title = 'Hello'
42
+ const description = 'World'
43
+ const handleClick = () => console.log('clicked')
44
+ </script>
45
+ ```
46
+
47
+ ## Features
48
+
49
+ This plugin implements the `VueLanguagePlugin` interface, providing:
50
+
51
+ - **`getEmbeddedCodes`** - Identifies `<template lang="pug">` blocks
52
+ - **`resolveEmbeddedCode`** - Extracts Pug content as embedded code
53
+ - **`compileSFCTemplate`** - Compiles Pug to HTML, then parses it into an AST using `@vue/compiler-dom`
54
+
55
+ ## How it Works
56
+
57
+ 1. Uses `pug-lexer` to convert Pug syntax into tokens
58
+ 2. Uses `pug-parser` to parse tokens into an AST
59
+ 3. Traverses the AST to generate HTML while building a source map
60
+ 4. Uses `@vue/compiler-dom.parse` to parse the HTML
61
+ 5. Uses `@vue/compiler-dom.transform` to transform the AST
62
+ 6. Maps error and warning positions back to the original Pug code via the source map
63
+
64
+ ## Related Packages
6
65
 
7
- `$ npm i -D @vue/language-plugin-pug`
66
+ - [`@vue/language-core`](../language-core) - Core module
8
67
 
9
- 2. Add to `tsconfig.json`
68
+ ## License
10
69
 
11
- ```jsonc
12
- {
13
- "vueCompilerOptions": {
14
- "plugins": ["@vue/language-plugin-pug"]
15
- }
16
- }
17
- ```
70
+ [MIT](https://github.com/vuejs/language-tools/blob/master/LICENSE) License
package/lib/baseParse.js CHANGED
@@ -207,14 +207,21 @@ function baseParse(pugCode) {
207
207
  addPrevSpace(attrToken);
208
208
  if (attrToken.type === 'attribute') {
209
209
  let attrText = pugCode.substring(getDocOffset(attrToken.loc.start.line, attrToken.loc.start.column), getDocOffset(attrToken.loc.end.line, attrToken.loc.end.column));
210
- if (typeof attrToken.val === 'string' && attrText.indexOf('=') >= 0) {
210
+ if (typeof attrToken.val === 'string' && attrText.includes('=')) {
211
211
  let valText = attrToken.val;
212
212
  if (valText.startsWith('`') && valText.endsWith('`')) {
213
- if (valText.indexOf('"') === -1) {
214
- valText = `"${valText.slice(1, -1)}"`;
213
+ const innerContent = valText.slice(1, -1);
214
+ if (!innerContent.includes('"')) {
215
+ valText = `"${innerContent}"`;
216
+ }
217
+ else if (!innerContent.includes("'")) {
218
+ valText = `'${innerContent}'`;
215
219
  }
216
220
  else {
217
- valText = `'${valText.slice(1, -1)}'`;
221
+ // Both quote types present: convert inner single quotes to double quotes
222
+ // This allows using single quotes as the outer delimiter
223
+ // JavaScript accepts both 'str' and "str" for string literals
224
+ valText = `'${innerContent.replace(/'/g, '"')}'`;
218
225
  }
219
226
  }
220
227
  valText = valText.replace(/ \\\n/g, '//\n');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-plugin-pug",
3
- "version": "3.2.4",
3
+ "version": "3.2.5",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -13,7 +13,7 @@
13
13
  "directory": "packages/language-plugin-pug"
14
14
  },
15
15
  "dependencies": {
16
- "@volar/source-map": "2.4.27",
16
+ "@volar/source-map": "2.4.28",
17
17
  "muggle-string": "^0.4.1",
18
18
  "pug-lexer": "^5.0.1",
19
19
  "pug-parser": "^6.0.0",
@@ -22,7 +22,7 @@
22
22
  "devDependencies": {
23
23
  "@types/node": "^22.10.4",
24
24
  "@vue/compiler-dom": "^3.5.0",
25
- "@vue/language-core": "3.2.4"
25
+ "@vue/language-core": "3.2.5"
26
26
  },
27
- "gitHead": "f0ede303fadb192a59068b4b667b0405523d24c8"
27
+ "gitHead": "ee5041d27940cf6f9a5150635d3b13140a9dff54"
28
28
  }