Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix templateUrl regexp for the single line component decorator #44

Merged
merged 1 commit into from
Jan 16, 2017
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
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 *:(.*)$/gm;
var templateUrlRegex = /templateUrl\s*:(\s*['"`](.*?)['"`]([,}\n]))/gm;
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['"])((?:[^\\]\\\1|.)*?)\1/g;

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

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

module.exports = componentWithSingleLineDecorator;
2 changes: 2 additions & 0 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ var componentWithQuoteInUrls = require('./component_with_quote_in_urls.js');
var componentWithMultipleStyles = require('./component_with_multiple_styles.js');
var componentWithoutRelPeriodSlash = require('./component_without_relative_period_slash.js');
var componentWithSpacing = require('./component_with_spacing.js');
var componentWithSingleLineDecorator = require('./component_with_single_line_decorator.js');

exports.simpleAngular2TestComponentFileStringSimple = sampleAngular2ComponentSimpleFixture;
exports.componentWithQuoteInUrls = componentWithQuoteInUrls;
exports.componentWithMultipleStyles = componentWithMultipleStyles;
exports.componentWithoutRelPeriodSlash = componentWithoutRelPeriodSlash;
exports.componentWithSpacing = componentWithSpacing;
exports.componentWithSingleLineDecorator = componentWithSingleLineDecorator;
19 changes: 17 additions & 2 deletions test/loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ describe("loader", function() {
});

it("Should convert partial string match requires", function() {
loader.call({}, `templateUrl: './index/app.html'`)
loader.call({}, `{templateUrl: './index/app.html'}`)
.should
.be
.eql(`template: require('./index/app.html')`);
.eql(`{template: require('./index/app.html')}`);
});

it("Should handle the absense of proper relative path notation", function() {
Expand Down Expand Up @@ -160,4 +160,19 @@ describe("loader", function() {

});

it("Should convert html and style file strings to require()s in a single line component decorator", function() {

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

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

});

});