From 135822eea3c7a15569b353e83547b73a40945ebf Mon Sep 17 00:00:00 2001 From: Archimedes Smith Date: Wed, 8 Aug 2018 19:51:15 +0100 Subject: [PATCH] fix: support backtick quoted templateUrl --- __tests__/preprocessor.test.js | 16 ++++++++++++++-- preprocessor.js | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/__tests__/preprocessor.test.js b/__tests__/preprocessor.test.js index 511240569c..bf3cf43973 100644 --- a/__tests__/preprocessor.test.js +++ b/__tests__/preprocessor.test.js @@ -55,7 +55,19 @@ const sources = [ '../media-box.component.scss', './media-box-h0.component.scss' ], -})` +})`, + // double quote + `@Component({ + selector: 'xc-media-box-h0', + templateUrl: "./media-box-h0.component.html", + styleUrls: [ '../media-box.component.scss' ], +})`, + // backtick + `@Component({ + selector: 'xc-media-box-h0', + templateUrl: \`./media-box-h0.component.html\`, + styleUrls: [ '../media-box.component.scss' ], +})`, ]; const config = { @@ -72,7 +84,7 @@ sources.forEach(source => { const result = process(source, '', config); expect(result).toMatch('styles: []'); expect(result).toMatch( - "template: require('./media-box-h0.component.html')" + /template: require\(['"`]\.\/media-box-h0\.component\.html['"`]\)/ ); }); }); diff --git a/preprocessor.js b/preprocessor.js index 6234c9fbce..0493dc4193 100644 --- a/preprocessor.js +++ b/preprocessor.js @@ -1,5 +1,5 @@ const process = require('ts-jest').process; -const TEMPLATE_URL_REGEX = /templateUrl\s*:\s*('|")(\.\/){0,}(.*)('|")/g; +const TEMPLATE_URL_REGEX = /templateUrl\s*:\s*('|"|`)(\.\/){0,}(.*)('|"|`)/g; const STYLE_URLS_REGEX = /styleUrls\s*:\s*\[[^\]]*\]/g; const ESCAPE_TEMPLATE_REGEX = /(\${|\`)/g;