Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions packages/ngtools/webpack/src/ivy/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}

Expand Down
72 changes: 0 additions & 72 deletions packages/ngtools/webpack/src/transformers/replace_resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}