@@ -5,6 +5,11 @@ import {
55 AttributeNode ,
66 MustacheTagNode ,
77 AttributeShorthandNode ,
8+ HeadNode ,
9+ InlineComponentNode ,
10+ SlotNode ,
11+ TitleNode ,
12+ WindowNode ,
813} from './nodes' ;
914import { inlineElements , TagName } from '../lib/elements' ;
1015import { FastPath } from 'prettier' ;
@@ -109,14 +114,17 @@ export function isIgnoreDirective(node: Node | undefined | null): boolean {
109114 return ! ! node && node . type === 'Comment' && node . data . trim ( ) === 'prettier-ignore' ;
110115}
111116
112- export function printRaw ( node : Node ) : string {
113- const children : Node [ ] | undefined = ( node as ElementNode ) . children ;
114-
115- if ( children ) {
116- return children . map ( printRaw ) . join ( '' ) ;
117- } else {
118- return ( node as TextNode ) . raw || '' ;
117+ export function printRaw (
118+ node : ElementNode | InlineComponentNode | SlotNode | WindowNode | HeadNode | TitleNode ,
119+ originalText : string ,
120+ ) : string {
121+ if ( node . children . length === 0 ) {
122+ return '' ;
119123 }
124+
125+ const firstChild = node . children [ 0 ] ;
126+ const lastChild = node . children [ node . children . length - 1 ] ;
127+ return originalText . substring ( firstChild . start , lastChild . end ) ;
120128}
121129
122130function isTextNode ( node : Node ) : node is TextNode {
@@ -148,7 +156,7 @@ export function getAttributeTextValue(attributeName: string, node: Node): string
148156}
149157
150158function getLangAttribute ( node : Node ) : string | null {
151- const value = getAttributeTextValue ( 'lang' , node ) ;
159+ const value = getAttributeTextValue ( 'lang' , node ) || getAttributeTextValue ( 'type' , node ) ;
152160
153161 if ( value != null ) {
154162 return value . replace ( / ^ t e x t \/ / , '' ) ;
0 commit comments