Skip to content
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
var loaderUtils = require("loader-utils");

// using: regex, capture groups, and capture group variables.
var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]\s*([,}]))/gm;
var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)([^\\]['"`])\s*)/gm;
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['`"])((?:[^\\]\\\1|.)*?)\1/g;

Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/component_with_comment_after_template_url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var componentWithCommentAfterTemplateUrl = `
import {Component} from '@angular/core';

@Component({
selector: 'test-component',
templateUrl: './some/path/to/file.html' /*my awesome template*/
})
export class TestComponent {}
`;

module.exports = componentWithCommentAfterTemplateUrl;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var componentWithCommentBetweenDecoratorAndClass = `
import {Component} from '@angular/core';

@Component({
selector: 'test-component',
templateUrl: './some/path/to/file.html',
styleUrls : ['./app/css/styles.css']
})

/*
* Comment
*/
export class TestComponent { }
`;

module.exports = componentWithCommentBetweenDecoratorAndClass;
12 changes: 12 additions & 0 deletions test/fixtures/component_with_only_template_url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var componentWithOnlyTemplateUrl = `
import {Component} from '@angular/core';

@Component({
selector: 'test-component',
templateUrl: './some/path/to/file.html'
//styleUrls: ['./app/css/styles.css']
})
export class TestComponent {}
`;

module.exports = componentWithOnlyTemplateUrl;
12 changes: 12 additions & 0 deletions test/fixtures/component_with_template_url_last.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var componentWithTemplateUrlLast = `
import {Component} from '@angular/core';

@Component({
selector: 'test-component',
styleUrls: ['./app/css/styles.css'],
templateUrl: './some/path/to/file.html'
})
export class TestComponent {}
`;

module.exports = componentWithTemplateUrlLast;
8 changes: 8 additions & 0 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ var componentWithoutRelPeriodSlash = require('./component_without_relative_perio
var componentWithSpacing = require('./component_with_spacing.js');
var componentWithSingleLineDecorator = require('./component_with_single_line_decorator.js');
var componentWithTemplateUrlEndingBySpace = require('./component_with_template_url_ending_by_space.js');
var componentWithTemplateUrlLast = require('./component_with_template_url_last.js');
var componentWithCommentAfterTemplateUrl = require('./component_with_comment_after_template_url.js');
var componentWithCommentBetweenDecoratorAndClass = require('./component_with_comment_between_decorator_and_class.js');
var componentWithOnlyTemplateUrl = require('./component_with_only_template_url.js');

exports.simpleAngularTestComponentFileStringSimple = sampleAngularComponentSimpleFixture;
exports.componentWithQuoteInUrls = componentWithQuoteInUrls;
Expand All @@ -13,3 +17,7 @@ exports.componentWithoutRelPeriodSlash = componentWithoutRelPeriodSlash;
exports.componentWithSpacing = componentWithSpacing;
exports.componentWithSingleLineDecorator = componentWithSingleLineDecorator;
exports.componentWithTemplateUrlEndingBySpace = componentWithTemplateUrlEndingBySpace;
exports.componentWithTemplateUrlLast = componentWithTemplateUrlLast;
exports.componentWithCommentAfterTemplateUrl = componentWithCommentAfterTemplateUrl;
exports.componentWithCommentBetweenDecoratorAndClass = componentWithCommentBetweenDecoratorAndClass;
exports.componentWithOnlyTemplateUrl = componentWithOnlyTemplateUrl;
77 changes: 77 additions & 0 deletions test/loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,82 @@ describe("loader", function() {
)

});
it("Should convert templateUrl properties when they appear last.", function() {

loader.call({}, fixtures.componentWithTemplateUrlLast)
.should
.be
.eql(`
import {Component} from '@angular/core';

@Component({
selector: 'test-component',
styles: [require('./app/css/styles.css')],
template: require('./some/path/to/file.html')
})
export class TestComponent {}
`
)

});

it("Should convert templateUrl properties when there is a comment after them.", function() {

loader.call({}, fixtures.componentWithCommentAfterTemplateUrl)
.should
.be
.eql(`
import {Component} from '@angular/core';

@Component({
selector: 'test-component',
template: require('./some/path/to/file.html') /*my awesome template*/
})
export class TestComponent {}
`
)

});

it("Should convert templateUrl properties when there is a comment between decorator and class.", function() {

loader.call({}, fixtures.componentWithCommentBetweenDecoratorAndClass)
.should
.be
.eql(`
import {Component} from '@angular/core';

@Component({
selector: 'test-component',
template: require('./some/path/to/file.html'),
styles: [require('./app/css/styles.css')]
})

/*
* Comment
*/
export class TestComponent { }
`
)

});

it("Should convert templateUrl properties when there is no styles or stylesUrl property.", function() {

loader.call({}, fixtures.componentWithOnlyTemplateUrl)
.should
.be
.eql(`
import {Component} from '@angular/core';

@Component({
selector: 'test-component',
template: require('./some/path/to/file.html')
//styles: [require('./app/css/styles.css')]
})
export class TestComponent {}
`
)

});
});