prettier-plugin-bootstrap 0.1.0 → 0.1.2

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/README.md +10 -0
  2. package/dist/index.js +19 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -85,6 +85,16 @@ Unknown classes are preserved in their original relative order and placed after
85
85
  - `acorn` / `meriyah` — Alternative JS parsers
86
86
  - `astro` — Astro components (requires `prettier-plugin-astro`)
87
87
 
88
+ ### Astro
89
+
90
+ When using with `prettier-plugin-astro`, list `prettier-plugin-bootstrap` **after** `prettier-plugin-astro` in your config so it can wrap the Astro parser:
91
+
92
+ ```json
93
+ {
94
+ "plugins": ["prettier-plugin-astro", "prettier-plugin-bootstrap"]
95
+ }
96
+ ```
97
+
88
98
  ## Development
89
99
 
90
100
  ```bash
package/dist/index.js CHANGED
@@ -375,9 +375,15 @@ const options = {
375
375
  description: "Function names whose arguments are Bootstrap class lists (e.g. clsx, classNames)."
376
376
  }
377
377
  };
378
- function createParserWrapper(parserName, processAst) {
378
+ function createParserWrapper(parserName, processAst, astFormat) {
379
379
  const wrapper = {
380
- astFormat: parserName === "html" || parserName === "vue" || parserName === "angular" ? "html" : "estree",
380
+ astFormat,
381
+ locStart(node) {
382
+ return node.range?.[0] ?? node.start ?? node.sourceSpan?.start?.offset ?? 0;
383
+ },
384
+ locEnd(node) {
385
+ return node.range?.[1] ?? node.end ?? node.sourceSpan?.end?.offset ?? 0;
386
+ },
381
387
  async parse(text, options) {
382
388
  const plugins = options.plugins || [];
383
389
  let originalParser = null;
@@ -393,21 +399,23 @@ function createParserWrapper(parserName, processAst) {
393
399
  }
394
400
  }
395
401
  if (!originalParser) throw new Error(`prettier-plugin-bootstrap: could not find the "${parserName}" parser. Make sure Prettier and the relevant parser plugin are installed.`);
402
+ if (originalParser.locStart) wrapper.locStart = originalParser.locStart;
403
+ if (originalParser.locEnd) wrapper.locEnd = originalParser.locEnd;
396
404
  return processAst(await originalParser.parse(text, options), [...DEFAULT_ATTRIBUTES, ...options.bootstrapAttributes || []]);
397
405
  }
398
406
  };
399
407
  return wrapper;
400
408
  }
401
409
  const parsers = {
402
- html: createParserWrapper("html", processHtmlAst),
403
- vue: createParserWrapper("vue", processHtmlAst),
404
- angular: createParserWrapper("angular", processHtmlAst),
405
- babel: createParserWrapper("babel", processJsxAst),
406
- "babel-ts": createParserWrapper("babel-ts", processJsxAst),
407
- typescript: createParserWrapper("typescript", processJsxAst),
408
- acorn: createParserWrapper("acorn", processJsxAst),
409
- meriyah: createParserWrapper("meriyah", processJsxAst),
410
- astro: createParserWrapper("astro", processHtmlAst)
410
+ html: createParserWrapper("html", processHtmlAst, "html"),
411
+ vue: createParserWrapper("vue", processHtmlAst, "html"),
412
+ angular: createParserWrapper("angular", processHtmlAst, "html"),
413
+ babel: createParserWrapper("babel", processJsxAst, "estree"),
414
+ "babel-ts": createParserWrapper("babel-ts", processJsxAst, "estree"),
415
+ typescript: createParserWrapper("typescript", processJsxAst, "estree"),
416
+ acorn: createParserWrapper("acorn", processJsxAst, "estree"),
417
+ meriyah: createParserWrapper("meriyah", processJsxAst, "estree"),
418
+ astro: createParserWrapper("astro", processHtmlAst, "astro")
411
419
  };
412
420
  //#endregion
413
421
  export { BREAKPOINTS, CLASS_ORDER, classKey, options, parsers, sortClasses };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prettier-plugin-bootstrap",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A Prettier plugin for automatic Bootstrap class sorting",
5
5
  "license": "MIT",
6
6
  "type": "module",