Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,43 @@ describe('@ngtools/webpack transformers', () => {
expect(oneLine`${result}`).toEqual(oneLine`${output}`);
});

it('should replace resources with backticks', () => {
const input = stripIndent`
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
templateUrl: \`./app.component.html\`,
styleUrls: [\`./app.component.css\`, \`./app.component.2.css\`]
})
export class AppComponent {
title = 'app';
}
`;
const output = stripIndent`
import * as tslib_1 from "tslib";
import { Component } from '@angular/core';
let AppComponent = class AppComponent {
constructor() {
this.title = 'app';
}
};
AppComponent = tslib_1.__decorate([
Component({
selector: 'app-root',
template: require("./app.component.html"),
styles: [require("./app.component.css"), require("./app.component.2.css")]
})
], AppComponent);
export { AppComponent };
`;

const transformer = replaceResources(() => true);
const result = transformTypescript(input, [transformer]);

expect(oneLine`${result}`).toEqual(oneLine`${output}`);
});

it('should not replace resources if shouldTransform returns false', () => {
const input = stripIndent`
import { Component } from '@angular/core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ function _getContentOfKeyLiteral(node?: ts.Node): string | null {
}

function _getResourceRequest(element: ts.Expression, sourceFile: ts.SourceFile) {
if (element.kind == ts.SyntaxKind.StringLiteral) {
if (
element.kind === ts.SyntaxKind.StringLiteral ||
element.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral
) {
const url = (element as ts.StringLiteral).text;
// If the URL does not start with ./ or ../, prepends ./ to it.
return `${/^\.?\.\//.test(url) ? '' : './'}${url}`;
Expand Down