Skip to content

Commit

Permalink
fix(transformers): handle single string styles or styleUrl property (#…
Browse files Browse the repository at this point in the history
…2186)

thanks!
  • Loading branch information
leosvelperez authored Nov 11, 2023
1 parent cc5cec2 commit cf00f55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
16 changes: 15 additions & 1 deletion src/transformers/replace-resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit cf00f55

Please sign in to comment.