Skip to content

Commit 0c99aae

Browse files
leosvelperezAnh Pham
authored andcommitted
fix(transformers): handle single string styles or styleUrl property (#2186)
thanks! (cherry picked from commit cf00f55)
1 parent 26b12ed commit 0c99aae

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
export const TEMPLATE_URL = 'templateUrl';
33
/** Angular component decorator styleUrls property name */
44
export const STYLE_URLS = 'styleUrls';
5+
/** Angular component decorator styleUrl property name */
6+
export const STYLE_URL = 'styleUrl';
57
/** Angular component decorator styles property name */
68
export const STYLES = 'styles';
79
/** Angular component decorator template property name */

src/transformers/replace-resources.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import type { TsCompilerInstance } from 'ts-jest';
99
import ts from 'typescript';
1010

11-
import { STYLES, STYLE_URLS, TEMPLATE_URL, TEMPLATE, REQUIRE, COMPONENT } from '../constants';
11+
import { STYLES, STYLE_URLS, TEMPLATE_URL, TEMPLATE, REQUIRE, COMPONENT, STYLE_URL } from '../constants';
1212

1313
const isAfterVersion = (targetMajor: number, targetMinor: number): boolean => {
1414
const [major, minor] = ts.versionMajorMinor.split('.').map((part) => parseInt(part));
@@ -225,12 +225,26 @@ function visitComponentMetadata(
225225
return nodeFactory.updatePropertyAssignment(node, nodeFactory.createIdentifier(TEMPLATE), importName);
226226

227227
case STYLES:
228+
if (!ts.isArrayLiteralExpression(node.initializer) && !ts.isStringLiteral(node.initializer)) {
229+
return node;
230+
}
231+
232+
return undefined;
233+
228234
case STYLE_URLS:
229235
if (!ts.isArrayLiteralExpression(node.initializer)) {
230236
return node;
231237
}
232238

233239
return undefined;
240+
241+
case STYLE_URL:
242+
if (!ts.isStringLiteral(node.initializer)) {
243+
return node;
244+
}
245+
246+
return undefined;
247+
234248
default:
235249
return node;
236250
}

0 commit comments

Comments
 (0)