diff --git a/packages/ngtools/webpack/src/ivy/host.ts b/packages/ngtools/webpack/src/ivy/host.ts index 59b5fcbcc4e3..3a7f3783bfb4 100644 --- a/packages/ngtools/webpack/src/ivy/host.ts +++ b/packages/ngtools/webpack/src/ivy/host.ts @@ -13,7 +13,6 @@ import * as path from 'path'; import * as ts from 'typescript'; import { NgccProcessor } from '../ngcc_processor'; import { WebpackResourceLoader } from '../resource_loader'; -import { workaroundStylePreprocessing } from '../transformers'; import { normalizePath } from './paths'; export function augmentHostWithResources( @@ -363,11 +362,6 @@ export function augmentHostWithCaching( ); if (file) { - // Temporary workaround for upstream transform resource defect - if (file && !file.isDeclarationFile && file.text.includes('@Component')) { - workaroundStylePreprocessing(file); - } - cache.set(fileName, file); } diff --git a/packages/ngtools/webpack/src/transformers/replace_resources.ts b/packages/ngtools/webpack/src/transformers/replace_resources.ts index cdfd5dccd8b7..b6c9cf160603 100644 --- a/packages/ngtools/webpack/src/transformers/replace_resources.ts +++ b/packages/ngtools/webpack/src/transformers/replace_resources.ts @@ -337,75 +337,3 @@ function getDecoratorOrigin( return null; } - -export function workaroundStylePreprocessing(sourceFile: ts.SourceFile): void { - const visitNode: ts.Visitor = (node: ts.Node) => { - if (ts.isClassDeclaration(node) && node.decorators?.length) { - for (const decorator of node.decorators) { - visitDecoratorWorkaround(decorator); - } - } - - return ts.forEachChild(node, visitNode); - }; - - ts.forEachChild(sourceFile, visitNode); -} - -function visitDecoratorWorkaround(node: ts.Decorator): void { - if (!ts.isCallExpression(node.expression)) { - return; - } - - const decoratorFactory = node.expression; - if ( - !ts.isIdentifier(decoratorFactory.expression) || - decoratorFactory.expression.text !== 'Component' - ) { - return; - } - - const args = decoratorFactory.arguments; - if (args.length !== 1 || !ts.isObjectLiteralExpression(args[0])) { - // Unsupported component metadata - return; - } - - const objectExpression = args[0] as ts.ObjectLiteralExpression; - - // check if a `styles` property is present - let hasStyles = false; - for (const element of objectExpression.properties) { - if (!ts.isPropertyAssignment(element) || ts.isComputedPropertyName(element.name)) { - continue; - } - - if (element.name.text === 'styles') { - hasStyles = true; - break; - } - } - - if (hasStyles) { - return; - } - - const nodeFactory = ts.factory; - - // add a `styles` property to workaround upstream compiler defect - const emptyArray = nodeFactory.createArrayLiteralExpression(); - const stylePropertyName = nodeFactory.createIdentifier('styles'); - const styleProperty = nodeFactory.createPropertyAssignment(stylePropertyName, emptyArray); - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (stylePropertyName.parent as any) = styleProperty; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (emptyArray.parent as any) = styleProperty; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (styleProperty.parent as any) = objectExpression; - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (objectExpression.properties as any) = nodeFactory.createNodeArray([ - ...objectExpression.properties, - styleProperty, - ]); -}