Skip to content

Commit 12c14b5

Browse files
clydinfilipesilva
authored andcommitted
fix(@ngtools/webpack): remove no longer needed component styles workaround
The underlying Angular compiler issue was corrected prior to the final release of 12.0.0 via angular/angular@a5fe8b9
1 parent b150093 commit 12c14b5

File tree

2 files changed

+0
-78
lines changed

2 files changed

+0
-78
lines changed

packages/ngtools/webpack/src/ivy/host.ts

-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import * as path from 'path';
1313
import * as ts from 'typescript';
1414
import { NgccProcessor } from '../ngcc_processor';
1515
import { WebpackResourceLoader } from '../resource_loader';
16-
import { workaroundStylePreprocessing } from '../transformers';
1716
import { normalizePath } from './paths';
1817

1918
export function augmentHostWithResources(
@@ -363,11 +362,6 @@ export function augmentHostWithCaching(
363362
);
364363

365364
if (file) {
366-
// Temporary workaround for upstream transform resource defect
367-
if (file && !file.isDeclarationFile && file.text.includes('@Component')) {
368-
workaroundStylePreprocessing(file);
369-
}
370-
371365
cache.set(fileName, file);
372366
}
373367

packages/ngtools/webpack/src/transformers/replace_resources.ts

-72
Original file line numberDiff line numberDiff line change
@@ -337,75 +337,3 @@ function getDecoratorOrigin(
337337

338338
return null;
339339
}
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

Comments
 (0)