Skip to content

support for components with spacing after styleUrls and templateUrl properties #11

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

Merged
merged 1 commit into from
Jul 3, 2016
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
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// using: regex, capture groups, and capture group variables.
var templateUrlRegex = /templateUrl:(.*)$/gm;
var stylesRegex = /styleUrls:(\s*\[[^\]]*?\])/g;
var templateUrlRegex = /templateUrl *:(.*)$/gm;
var stylesRegex = /styleUrls *:(\s*\[[^\]]*?\])/g;
var stringRegex = /(['"])((?:[^\\]\\\1|.)*?)\1/g;

function replaceStringsWithRequires(string) {
Expand Down
12 changes: 12 additions & 0 deletions test/fixtures/component_with_spacing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var componentWithSpacing = `
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 = componentWithSpacing;
2 changes: 2 additions & 0 deletions test/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ var sampleAngular2ComponentSimpleFixture = require('./sample_angular2_component_
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');

exports.simpleAngular2TestComponentFileStringSimple = sampleAngular2ComponentSimpleFixture;
exports.componentWithQuoteInUrls = componentWithQuoteInUrls;
exports.componentWithMultipleStyles = componentWithMultipleStyles;
exports.componentWithoutRelPeriodSlash = componentWithoutRelPeriodSlash;
exports.componentWithSpacing = componentWithSpacing;

18 changes: 18 additions & 0 deletions test/loader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,23 @@ describe("loader", function() {
);
});

it("Should convert html and style file strings to require()s regardless of spacing", function(){

loader.call({}, fixtures.componentWithSpacing)
.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 {}
`
)

});

});