1- import type { AttributeNode , DirectiveNode , ElementNode , ParentNode } from '@vue/compiler-dom'
1+ import type { AttributeNode , DirectiveNode , ParentNode } from '@vue/compiler-dom'
22import type { TransformResult } from 'vite'
33import type { CreateJsHandlerOptions , ICustomAttributesEntities , JsHandler } from '@/types'
44import { NodeTypes } from '@vue/compiler-dom'
@@ -7,7 +7,6 @@ import MagicString from 'magic-string'
77import { generateCode , replaceWxml } from '@/wxml'
88import { createAttributeMatcher } from '@/wxml/custom-attributes'
99import { shouldEnableComponentLocalStyle , UniAppXComponentLocalStyleCollector } from './component-local-style'
10- import { UniAppXSpaceStyleCollector } from './space-style'
1110
1211function traverse ( node : ParentNode , visitor : ( node : ParentNode ) => void ) : void {
1312 visitor ( node )
@@ -128,11 +127,6 @@ const defaultCreateJsHandlerOptions: CreateJsHandlerOptions = {
128127}
129128const UVUE_NVUE_RE = / \. (?: u v u e | n v u e ) (?: \? .* ) ? $ /
130129
131- function insertClassAttribute ( ms : MagicString , node : ElementNode , className : string ) {
132- const insertOffset = node . loc . start . offset + 1 + node . tag . length
133- ms . appendLeft ( insertOffset , ` class="${ className } "` )
134- }
135-
136130export function transformUVue (
137131 code : string ,
138132 id : string ,
@@ -147,18 +141,11 @@ export function transformUVue(
147141 const matchCustomAttribute = createAttributeMatcher ( customAttributesEntities )
148142 const ms = new MagicString ( code )
149143 const { descriptor, errors } = parse ( code )
150- const spaceStyleCollector = new UniAppXSpaceStyleCollector ( id )
151144 const localStyleCollector = options . enableComponentLocalStyle && shouldEnableComponentLocalStyle ( id )
152145 ? new UniAppXComponentLocalStyleCollector ( id , runtimeSet )
153146 : undefined
154147 if ( errors . length === 0 ) {
155148 if ( descriptor . template ?. ast ) {
156- traverse ( descriptor . template . ast , ( node ) => {
157- if ( node . type === NodeTypes . ELEMENT ) {
158- spaceStyleCollector . collect ( node )
159- }
160- } )
161-
162149 traverse ( descriptor . template . ast , ( node ) => {
163150 if ( node . type !== NodeTypes . ELEMENT ) {
164151 return
@@ -175,14 +162,11 @@ export function transformUVue(
175162 if ( ! shouldHandle ) {
176163 continue
177164 }
178- const staticClassRewrite = shouldHandleDefault
179- ? spaceStyleCollector . getStaticClassRewrite ( prop )
180- : undefined
181165 if ( shouldHandleDefault && localStyleCollector ) {
182- updateStaticAttributeWithLocalStyle ( ms , prop , localStyleCollector , staticClassRewrite )
166+ updateStaticAttributeWithLocalStyle ( ms , prop , localStyleCollector )
183167 }
184168 else {
185- updateStaticAttribute ( ms , prop , staticClassRewrite )
169+ updateStaticAttribute ( ms , prop )
186170 }
187171 if ( shouldHandleDefault ) {
188172 continue
@@ -204,29 +188,20 @@ export function transformUVue(
204188 if ( ! shouldHandle ) {
205189 continue
206190 }
207- const directiveExpressionRewrite = attrName . toLowerCase ( ) === 'class'
208- ? spaceStyleCollector . getDirectiveExpressionRewrite ( prop )
209- : undefined
210191 if ( attrName . toLowerCase ( ) === 'class' && localStyleCollector ) {
211192 updateDirectiveExpressionWithLocalStyle (
212193 ms ,
213194 prop ,
214195 jsHandler ,
215196 localStyleCollector ,
216197 runtimeSet ,
217- directiveExpressionRewrite ,
218198 )
219199 }
220200 else {
221- updateDirectiveExpression ( ms , prop , jsHandler , runtimeSet , directiveExpressionRewrite )
201+ updateDirectiveExpression ( ms , prop , jsHandler , runtimeSet )
222202 }
223203 }
224204 }
225-
226- const insertedClass = spaceStyleCollector . getInsertedClass ( node )
227- if ( insertedClass ) {
228- insertClassAttribute ( ms , node , insertedClass )
229- }
230205 } )
231206 }
232207
@@ -252,9 +227,6 @@ export function transformUVue(
252227 if ( localStyleCollector ?. hasStyles ( ) ) {
253228 ms . append ( `\n${ localStyleCollector . toStyleBlock ( ) } ` )
254229 }
255- if ( spaceStyleCollector . hasStyles ( ) ) {
256- ms . append ( `\n${ spaceStyleCollector . toStyleBlock ( ) } ` )
257- }
258230 }
259231 return {
260232 code : ms . toString ( ) ,
0 commit comments