Skip to content

Commit 98f3058

Browse files
authored
refactor(transformer): revert possibility of testing styles (#930)
Revert #900
1 parent 03618e5 commit 98f3058

File tree

4 files changed

+15
-69
lines changed

4 files changed

+15
-69
lines changed

e2e/ast-transformers/replace-resources/__tests__/bar.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ test(
2727

2828
const elementToFind = fixture.debugElement.nativeElement.querySelector('p');
2929
expect(elementToFind).toBeDefined();
30-
expect(window.getComputedStyle(elementToFind).color).toEqual('red');
30+
expect(window.getComputedStyle(elementToFind).color).toEqual('');
3131
expect(window.getComputedStyle(elementToFind).fontSize).toEqual('');
3232
}),
3333
);

e2e/custom-typings/yarn.lock

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
1-
# This file is generated by running "yarn install" inside your project.
2-
# Manual changes might be lost - proceed with caution!
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
33

4-
__metadata:
5-
version: 4
6-
cacheKey: 7
74

8-
"@types/jquery@npm:^3.5.5":
9-
version: 3.5.5
10-
resolution: "@types/jquery@npm:3.5.5"
5+
"@types/jquery@^3.5.5":
6+
version "3.5.5"
7+
resolved "https://registry.yarnpkg.com/@types/jquery/-/jquery-3.5.5.tgz#2c63f47c9c8d96693d272f5453602afd8338c903"
8+
integrity sha512-6RXU9Xzpc6vxNrS6FPPapN1SxSHgQ336WC6Jj/N8q30OiaBZ00l1GBgeP7usjVZPivSkGUfL1z/WW6TX989M+w==
119
dependencies:
12-
"@types/sizzle": "*"
13-
checksum: 9e3c34451577c6916ac9de8a26fd8bce2831cb5861116514cba4a984189067635a3e084039308324d8e20bfa5f2e1ce7725a509110e5e05487b91f9369b1ae43
14-
languageName: node
15-
linkType: hard
10+
"@types/sizzle" "*"
1611

17-
"@types/sizzle@npm:*":
18-
version: 2.3.3
19-
resolution: "@types/sizzle@npm:2.3.3"
20-
checksum: 8f019f9e1b110b4fdfc08f8a3a8b8b87118a11f3ba11e159541b17f17498c0ef95e8efa0b818c9fed6911041f6b71ef8d44cf8c1c83b4cbb7bd14e4248892f4c
21-
languageName: node
22-
linkType: hard
23-
24-
"root-workspace-0b6124@workspace:.":
25-
version: 0.0.0-use.local
26-
resolution: "root-workspace-0b6124@workspace:."
27-
dependencies:
28-
"@types/jquery": ^3.5.5
29-
languageName: unknown
30-
linkType: soft
12+
"@types/sizzle@*":
13+
version "2.3.3"
14+
resolved "https://registry.yarnpkg.com/@types/sizzle/-/sizzle-2.3.3.tgz#ff5e2f1902969d305225a047c8a0fd5c915cebef"
15+
integrity sha512-JYM8x9EGF163bEyhdJBpR2QX1R5naCJHC8ucJylJ3w9/CVBaskdQ8WqBf8MmQrd1kRvp/a4TS8HJ+bxzR7ZJYQ==

src/__tests__/__snapshots__/replace-resources.spec.ts.snap

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ AppComponent = tslib_1.__decorate([
1515
core_1.Component({
1616
selector: 'app-root',
1717
template: require(\\"./app.component.html\\"),
18-
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
1918
})
2019
], AppComponent);
2120
exports.AppComponent = AppComponent;
@@ -35,7 +34,6 @@ AppComponent = __decorate([
3534
Component({
3635
selector: 'app-root',
3736
template: __NG_CLI_RESOURCE__0,
38-
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
3937
})
4038
], AppComponent);
4139
export { AppComponent };
@@ -57,7 +55,6 @@ FooComponent = tslib_1.__decorate([
5755
core_1.Component({
5856
selector: 'app-root',
5957
template: \`<h1>Foo Bar</h1>\`,
60-
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
6158
})
6259
], FooComponent);
6360
exports.FooComponent = FooComponent;
@@ -76,7 +73,6 @@ FooComponent = __decorate([
7673
Component({
7774
selector: 'app-root',
7875
template: \`<h1>Foo Bar</h1>\`,
79-
styles: [\\"\\\\n h1 {\\\\n font-size: 1.6rem;\\\\n }\\\\n \\"]
8076
})
8177
], FooComponent);
8278
export { FooComponent };

src/transformers/replace-resources.ts

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const shouldTransform = (fileName: string) => !fileName.endsWith('.ngfactory.ts'
1717
*
1818
* Check `@Component` to do following things:
1919
* - Replace `templateUrl` path with `require` for `CommonJS` or a constant with `import` for `ESM`
20-
* - Combine `styles` and `styleUrls` to become `styles` with empty array as value because we don't test css
20+
* - Remove `styles` and `styleUrls` because we don't test css
2121
*
2222
* @example
2323
*
@@ -33,7 +33,6 @@ const shouldTransform = (fileName: string) => !fileName.endsWith('.ngfactory.ts'
3333
* @Component({
3434
* selector: 'foo',
3535
* templateUrl: require('./foo.component.html'),
36-
* styles: [],
3736
* })
3837
*
3938
* or for `ESM`
@@ -42,7 +41,6 @@ const shouldTransform = (fileName: string) => !fileName.endsWith('.ngfactory.ts'
4241
* @Component({
4342
* selector: 'foo',
4443
* templateUrl: __NG_CLI_RESOURCE__0,
45-
* styles: [],
4644
* })
4745
*/
4846
export function replaceResources({ program }: TsCompilerInstance): ts.TransformerFactory<ts.SourceFile> {
@@ -141,7 +139,7 @@ function visitDecorator(
141139
// visit all properties
142140
let properties = ts.visitNodes(objectExpression.properties, (node) =>
143141
ts.isObjectLiteralElementLike(node)
144-
? visitComponentMetadata(nodeFactory, node, styleReplacements, resourceImportDeclarations, moduleKind)
142+
? visitComponentMetadata(nodeFactory, node, resourceImportDeclarations, moduleKind)
145143
: node,
146144
);
147145

@@ -180,7 +178,6 @@ function visitDecorator(
180178
function visitComponentMetadata(
181179
nodeFactory: ts.NodeFactory,
182180
node: ts.ObjectLiteralElementLike,
183-
styleReplacements: ts.Expression[],
184181
resourceImportDeclarations: ts.ImportDeclaration[],
185182
moduleKind?: ts.ModuleKind,
186183
): ts.ObjectLiteralElementLike | undefined {
@@ -208,38 +205,6 @@ function visitComponentMetadata(
208205
: ts.updatePropertyAssignment(node, ts.createIdentifier(TEMPLATE), importName);
209206

210207
case STYLES:
211-
if (!ts.isArrayLiteralExpression(node.initializer)) {
212-
return node;
213-
}
214-
const isInlineStyles = name === STYLES;
215-
// @ts-expect-error should be fine
216-
const styles = ts.visitNodes(node.initializer.elements, (node) => {
217-
if (!ts.isStringLiteral(node) && !ts.isNoSubstitutionTemplateLiteral(node)) {
218-
return node;
219-
}
220-
221-
let url;
222-
if (isInlineStyles) {
223-
return useNodeFactory ? nodeFactory.createStringLiteral(node.text) : ts.createLiteral(node.text);
224-
} else {
225-
url = getResourceUrl(node);
226-
}
227-
228-
if (!url) {
229-
return node;
230-
}
231-
232-
return createResourceImport(nodeFactory, url, resourceImportDeclarations, moduleKind);
233-
});
234-
235-
// Styles should be placed first
236-
if (isInlineStyles) {
237-
styleReplacements.unshift(...styles);
238-
} else {
239-
styleReplacements.push(...styles);
240-
}
241-
242-
return undefined;
243208
case STYLE_URLS:
244209
if (!ts.isArrayLiteralExpression(node.initializer)) {
245210
return node;
@@ -251,7 +216,7 @@ function visitComponentMetadata(
251216
}
252217
}
253218

254-
export function getResourceUrl(node: ts.Node): string | null {
219+
function getResourceUrl(node: ts.Node): string | null {
255220
// only analyze strings
256221
if (!ts.isStringLiteral(node) && !ts.isNoSubstitutionTemplateLiteral(node)) {
257222
return null;

0 commit comments

Comments
 (0)