From 0c99aae402c8c7edbef8b1c64d2a7e41a76a6b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Sat, 11 Nov 2023 11:41:55 +0100 Subject: [PATCH] fix(transformers): handle single string styles or styleUrl property (#2186) thanks! (cherry picked from commit cf00f55612f590bb26613e569338bc72eba4ba08) --- src/constants.ts | 2 ++ src/transformers/replace-resources.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/constants.ts b/src/constants.ts index bf4036663f..b18610f517 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,6 +2,8 @@ export const TEMPLATE_URL = 'templateUrl'; /** Angular component decorator styleUrls property name */ export const STYLE_URLS = 'styleUrls'; +/** Angular component decorator styleUrl property name */ +export const STYLE_URL = 'styleUrl'; /** Angular component decorator styles property name */ export const STYLES = 'styles'; /** Angular component decorator template property name */ diff --git a/src/transformers/replace-resources.ts b/src/transformers/replace-resources.ts index 32330e543d..3f62742eb4 100644 --- a/src/transformers/replace-resources.ts +++ b/src/transformers/replace-resources.ts @@ -8,7 +8,7 @@ import type { TsCompilerInstance } from 'ts-jest'; import ts from 'typescript'; -import { STYLES, STYLE_URLS, TEMPLATE_URL, TEMPLATE, REQUIRE, COMPONENT } from '../constants'; +import { STYLES, STYLE_URLS, TEMPLATE_URL, TEMPLATE, REQUIRE, COMPONENT, STYLE_URL } from '../constants'; const isAfterVersion = (targetMajor: number, targetMinor: number): boolean => { const [major, minor] = ts.versionMajorMinor.split('.').map((part) => parseInt(part)); @@ -225,12 +225,26 @@ function visitComponentMetadata( return nodeFactory.updatePropertyAssignment(node, nodeFactory.createIdentifier(TEMPLATE), importName); case STYLES: + if (!ts.isArrayLiteralExpression(node.initializer) && !ts.isStringLiteral(node.initializer)) { + return node; + } + + return undefined; + case STYLE_URLS: if (!ts.isArrayLiteralExpression(node.initializer)) { return node; } return undefined; + + case STYLE_URL: + if (!ts.isStringLiteral(node.initializer)) { + return node; + } + + return undefined; + default: return node; }