Skip to content

Commit ef1747e

Browse files
DetectiveQuackfilipesilva
authored andcommitted
fix(@angular/cli): allow backticks in templateUrl and styleUrls
1 parent 930437e commit ef1747e

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

Diff for: packages/@ngtools/webpack/src/transformers/replace_resources.spec.ts

+37
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,43 @@ describe('@ngtools/webpack transformers', () => {
4141
expect(oneLine`${result}`).toEqual(oneLine`${output}`);
4242
});
4343

44+
it('should replace resources with backticks', () => {
45+
const input = stripIndent`
46+
import { Component } from '@angular/core';
47+
48+
@Component({
49+
selector: 'app-root',
50+
templateUrl: \`./app.component.html\`,
51+
styleUrls: [\`./app.component.css\`, \`./app.component.2.css\`]
52+
})
53+
export class AppComponent {
54+
title = 'app';
55+
}
56+
`;
57+
const output = stripIndent`
58+
import * as tslib_1 from "tslib";
59+
import { Component } from '@angular/core';
60+
let AppComponent = class AppComponent {
61+
constructor() {
62+
this.title = 'app';
63+
}
64+
};
65+
AppComponent = tslib_1.__decorate([
66+
Component({
67+
selector: 'app-root',
68+
template: require("./app.component.html"),
69+
styles: [require("./app.component.css"), require("./app.component.2.css")]
70+
})
71+
], AppComponent);
72+
export { AppComponent };
73+
`;
74+
75+
const transformer = replaceResources(() => true);
76+
const result = transformTypescript(input, [transformer]);
77+
78+
expect(oneLine`${result}`).toEqual(oneLine`${output}`);
79+
});
80+
4481
it('should not replace resources if shouldTransform returns false', () => {
4582
const input = stripIndent`
4683
import { Component } from '@angular/core';

Diff for: packages/@ngtools/webpack/src/transformers/replace_resources.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ function _getContentOfKeyLiteral(node?: ts.Node): string | null {
131131
}
132132

133133
function _getResourceRequest(element: ts.Expression, sourceFile: ts.SourceFile) {
134-
if (element.kind == ts.SyntaxKind.StringLiteral) {
134+
if (
135+
element.kind === ts.SyntaxKind.StringLiteral ||
136+
element.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral
137+
) {
135138
const url = (element as ts.StringLiteral).text;
136139
// If the URL does not start with ./ or ../, prepends ./ to it.
137140
return `${/^\.?\.\//.test(url) ? '' : './'}${url}`;

0 commit comments

Comments
 (0)