11// @ts -ignore
2- import type { AttrDoubleQuoted , AttrSingleQuoted } from '@shopify/prettier-plugin-liquid/dist/types.js'
2+ import type * as Liquid from '@shopify/prettier-plugin-liquid/dist/types.js'
33import * as astTypes from 'ast-types'
44// @ts -ignore
55import jsesc from 'jsesc'
@@ -311,7 +311,7 @@ function transformLiquid(ast: any, env: TransformerEnv) {
311311
312312 let changes : StringChange [ ] = [ ]
313313
314- function sortAttribute ( attr : AttrSingleQuoted | AttrDoubleQuoted ) {
314+ function sortAttribute ( attr : Liquid . AttrSingleQuoted | Liquid . AttrDoubleQuoted ) {
315315 for ( let i = 0 ; i < attr . value . length ; i ++ ) {
316316 let node = attr . value [ i ]
317317 if ( node . type === 'TextNode' ) {
@@ -1010,7 +1010,9 @@ function transformSvelte(ast: any, env: TransformerEnv) {
10101010
10111011export { options } from './options.js'
10121012
1013- let html = defineTransform ( {
1013+ type HtmlNode = { type : 'attribute' ; name : string ; value : string } | { kind : 'attribute' ; name : string ; value : string }
1014+
1015+ let html = defineTransform < HtmlNode > ( {
10141016 parsers : {
10151017 html : { staticAttrs : [ 'class' ] } ,
10161018 lwc : { staticAttrs : [ 'class' ] } ,
@@ -1021,15 +1023,29 @@ let html = defineTransform({
10211023 transform : transformHtml ,
10221024} )
10231025
1024- let glimmer = defineTransform ( {
1026+ type GlimmerNode =
1027+ | { type : 'TextNode' ; chars : string }
1028+ | { type : 'StringLiteral' ; value : string }
1029+ | { type : 'ConcatStatement' ; parts : GlimmerNode [ ] }
1030+ | { type : 'SubExpression' ; path : { original : string } }
1031+ | { type : 'AttrNode' ; name : string ; value : GlimmerNode }
1032+
1033+ let glimmer = defineTransform < GlimmerNode > ( {
10251034 parsers : {
10261035 glimmer : { staticAttrs : [ 'class' ] } ,
10271036 } ,
10281037
10291038 transform : transformGlimmer ,
10301039} )
10311040
1032- let css = defineTransform ( {
1041+ type CssValueNode = { type : 'value-*' ; name : string ; params : string }
1042+ type CssNode = {
1043+ type : 'css-atrule'
1044+ name : string
1045+ params : string | CssValueNode
1046+ }
1047+
1048+ let css = defineTransform < CssNode > ( {
10331049 parsers : {
10341050 css : { } ,
10351051 scss : { } ,
@@ -1039,7 +1055,7 @@ let css = defineTransform({
10391055 transform : transformCss ,
10401056} )
10411057
1042- let js = defineTransform ( {
1058+ let js = defineTransform < import ( '@babel/types' ) . Node > ( {
10431059 parsers : {
10441060 babel : { staticAttrs : [ 'class' , 'className' ] } ,
10451061 'babel-flow' : { staticAttrs : [ 'class' , 'className' ] } ,
@@ -1053,14 +1069,23 @@ let js = defineTransform({
10531069 meriyah : { staticAttrs : [ 'class' , 'className' ] } ,
10541070 __js_expression : { staticAttrs : [ 'class' , 'className' ] } ,
10551071 ...( base . parsers . astroExpressionParser
1056- ? { astroExpressionParser : { staticAttrs : [ 'class' ] , dynamicAttrs : [ 'class:list' ] } }
1072+ ? {
1073+ astroExpressionParser : {
1074+ staticAttrs : [ 'class' ] ,
1075+ dynamicAttrs : [ 'class:list' ] ,
1076+ } ,
1077+ }
10571078 : { } ) ,
10581079 } ,
10591080
10601081 transform : transformJavaScript ,
10611082} )
10621083
1063- let svelte = defineTransform ( {
1084+ type SvelteNode = import ( 'svelte/compiler' ) . AST . SvelteNode & {
1085+ changes : StringChange [ ]
1086+ }
1087+
1088+ let svelte = defineTransform < SvelteNode > ( {
10641089 parsers : {
10651090 svelte : { staticAttrs : [ 'class' ] } ,
10661091 } ,
@@ -1090,7 +1115,20 @@ let svelte = defineTransform({
10901115 } ,
10911116} )
10921117
1093- let astro = defineTransform ( {
1118+ type AstroNode =
1119+ | { type : 'element' ; attributes : Extract < AstroNode , { type : 'attribute' } > [ ] }
1120+ | {
1121+ type : 'custom-element'
1122+ attributes : Extract < AstroNode , { type : 'attribute' } > [ ]
1123+ }
1124+ | {
1125+ type : 'component'
1126+ attributes : Extract < AstroNode , { type : 'attribute' } > [ ]
1127+ }
1128+ | { type : 'attribute' ; kind : 'quoted' ; name : string ; value : string }
1129+ | { type : 'attribute' ; kind : 'expression' ; name : string ; value : unknown }
1130+
1131+ let astro = defineTransform < AstroNode > ( {
10941132 parsers : {
10951133 astro : {
10961134 staticAttrs : [ 'class' , 'className' ] ,
@@ -1101,25 +1139,61 @@ let astro = defineTransform({
11011139 transform : transformAstro ,
11021140} )
11031141
1104- let marko = defineTransform ( {
1142+ type MarkoNode = import ( '@marko/compiler' ) . types . Node
1143+
1144+ let marko = defineTransform < MarkoNode > ( {
11051145 parsers : { marko : { staticAttrs : [ 'class' ] } } ,
11061146
11071147 transform : transformMarko ,
11081148} )
11091149
1110- let twig = defineTransform ( {
1150+ type TwigIdentifier = { type : 'Identifier' ; name : string }
1151+
1152+ type TwigMemberExpression = {
1153+ type : 'MemberExpression'
1154+ property : TwigIdentifier | TwigCallExpression | TwigMemberExpression
1155+ }
1156+
1157+ type TwigCallExpression = {
1158+ type : 'CallExpression'
1159+ callee : TwigIdentifier | TwigCallExpression | TwigMemberExpression
1160+ }
1161+
1162+ type TwigNode =
1163+ | { type : 'Attribute' ; name : TwigIdentifier }
1164+ | { type : 'StringLiteral' ; value : string }
1165+ | { type : 'BinaryConcatExpression' }
1166+ | { type : 'BinaryAddExpression' }
1167+ | TwigIdentifier
1168+ | TwigMemberExpression
1169+ | TwigCallExpression
1170+
1171+ let twig = defineTransform < TwigNode > ( {
11111172 parsers : { twig : { staticAttrs : [ 'class' ] } } ,
11121173
11131174 transform : transformTwig ,
11141175} )
11151176
1177+ interface PugNode {
1178+ content : string
1179+ tokens : import ( 'pug-lexer' ) . Token [ ]
1180+ }
1181+
11161182let pug = defineTransform ( {
11171183 parsers : { pug : { staticAttrs : [ 'class' ] } } ,
11181184
11191185 transform : transformPug ,
11201186} )
11211187
1122- let liquid = defineTransform ( {
1188+ type LiquidNode =
1189+ | Liquid . TextNode
1190+ | Liquid . AttributeNode
1191+ | Liquid . LiquidTag
1192+ | Liquid . HtmlElement
1193+ | Liquid . DocumentNode
1194+ | Liquid . LiquidExpression
1195+
1196+ let liquid = defineTransform < LiquidNode > ( {
11231197 parsers : { 'liquid-html' : { staticAttrs : [ 'class' ] } } ,
11241198
11251199 transform : transformLiquid ,
0 commit comments