File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ import type {
77} from "prettier" ;
88import { parse } from "./parser.js" ;
99import { print } from "./printer.js" ;
10+ import type { AnywhereNode } from "./types.js" ;
1011
1112/**
1213 * @see https://prettier.io/docs/en/plugins#languages
@@ -15,7 +16,6 @@ export const languages: Partial<SupportLanguage>[] = [
1516 {
1617 name : "Any HTML-like Languages" ,
1718 parsers : [ "anywhere" ] ,
18- aceMode : "text" ,
1919 } ,
2020] ;
2121
@@ -26,13 +26,8 @@ export const parsers: Record<string, Parser> = {
2626 anywhere : {
2727 parse,
2828 astFormat : "anywhere" ,
29- // there's only a single node
30- locStart ( node ) {
31- return node . start ;
32- } ,
33- locEnd ( node ) {
34- return node . end ;
35- } ,
29+ locStart : ( node : AnywhereNode ) => node . start ,
30+ locEnd : ( node : AnywhereNode ) => node . end ,
3631 } ,
3732} ;
3833
@@ -51,7 +46,7 @@ export const printers: Record<string, Printer> = {
5146export const options : Record < string , SupportOption > = {
5247 regex : {
5348 type : "string" ,
54- category : "Anywhere " ,
49+ category : "Format " ,
5550 default : 'class="([^"]*)"' ,
5651 description : "regex to match class attribute" ,
5752 } ,
Original file line number Diff line number Diff line change 1- import type { ParserOptions } from "prettier" ;
2- import { format } from "prettier" ;
1+ import { type ParserOptions , format } from "prettier" ;
32import * as prettierPluginTailwindcss from "prettier-plugin-tailwindcss" ;
4-
5- type AnywhereNode = {
6- type : "anywhere" ;
7- body : string ;
8- source : string ;
9- start : number ;
10- end : number ;
11- } ;
3+ import type { AnywhereNode } from "./types.js" ;
124
135export const parse = async (
146 text : string ,
@@ -42,10 +34,8 @@ export const parse = async (
4234 }
4335
4436 return {
45- type : "anywhere" ,
4637 body : formattedText ,
47- end : text . length ,
48- source : text ,
4938 start : 0 ,
39+ end : text . length ,
5040 } ;
5141} ;
Original file line number Diff line number Diff line change 11import type { AstPath , Doc } from "prettier" ;
2+ import type { AnywhereNode } from "./types.js" ;
23
34export const print = ( path : AstPath ) : Doc => {
4- const node = path . node ;
5-
6- switch ( node . type ) {
7- case "anywhere" : {
8- return node . body ;
9- }
10- }
11-
12- throw new Error ( `Unknown node type: ${ node . type } ` ) ;
5+ const node : AnywhereNode = path . node ;
6+ return node . body ;
137} ;
Original file line number Diff line number Diff line change 1+ export type AnywhereNode = {
2+ body : string ;
3+ start : number ;
4+ end : number ;
5+ } ;
You can’t perform that action at this time.
0 commit comments