@@ -337,75 +337,3 @@ function getDecoratorOrigin(
337
337
338
338
return null ;
339
339
}
340
-
341
- export function workaroundStylePreprocessing ( sourceFile : ts . SourceFile ) : void {
342
- const visitNode : ts . Visitor = ( node : ts . Node ) => {
343
- if ( ts . isClassDeclaration ( node ) && node . decorators ?. length ) {
344
- for ( const decorator of node . decorators ) {
345
- visitDecoratorWorkaround ( decorator ) ;
346
- }
347
- }
348
-
349
- return ts . forEachChild ( node , visitNode ) ;
350
- } ;
351
-
352
- ts . forEachChild ( sourceFile , visitNode ) ;
353
- }
354
-
355
- function visitDecoratorWorkaround ( node : ts . Decorator ) : void {
356
- if ( ! ts . isCallExpression ( node . expression ) ) {
357
- return ;
358
- }
359
-
360
- const decoratorFactory = node . expression ;
361
- if (
362
- ! ts . isIdentifier ( decoratorFactory . expression ) ||
363
- decoratorFactory . expression . text !== 'Component'
364
- ) {
365
- return ;
366
- }
367
-
368
- const args = decoratorFactory . arguments ;
369
- if ( args . length !== 1 || ! ts . isObjectLiteralExpression ( args [ 0 ] ) ) {
370
- // Unsupported component metadata
371
- return ;
372
- }
373
-
374
- const objectExpression = args [ 0 ] as ts . ObjectLiteralExpression ;
375
-
376
- // check if a `styles` property is present
377
- let hasStyles = false ;
378
- for ( const element of objectExpression . properties ) {
379
- if ( ! ts . isPropertyAssignment ( element ) || ts . isComputedPropertyName ( element . name ) ) {
380
- continue ;
381
- }
382
-
383
- if ( element . name . text === 'styles' ) {
384
- hasStyles = true ;
385
- break ;
386
- }
387
- }
388
-
389
- if ( hasStyles ) {
390
- return ;
391
- }
392
-
393
- const nodeFactory = ts . factory ;
394
-
395
- // add a `styles` property to workaround upstream compiler defect
396
- const emptyArray = nodeFactory . createArrayLiteralExpression ( ) ;
397
- const stylePropertyName = nodeFactory . createIdentifier ( 'styles' ) ;
398
- const styleProperty = nodeFactory . createPropertyAssignment ( stylePropertyName , emptyArray ) ;
399
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
400
- ( stylePropertyName . parent as any ) = styleProperty ;
401
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
402
- ( emptyArray . parent as any ) = styleProperty ;
403
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
404
- ( styleProperty . parent as any ) = objectExpression ;
405
-
406
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
407
- ( objectExpression . properties as any ) = nodeFactory . createNodeArray ( [
408
- ...objectExpression . properties ,
409
- styleProperty ,
410
- ] ) ;
411
- }
0 commit comments