diff --git a/index.js b/index.js index db58992..f7df93b 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test/fixtures/component_with_spacing.js b/test/fixtures/component_with_spacing.js new file mode 100644 index 0000000..011c93a --- /dev/null +++ b/test/fixtures/component_with_spacing.js @@ -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; diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 654d8e6..49f6f8e 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -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; diff --git a/test/loader.spec.js b/test/loader.spec.js index 4b83ce7..4f21849 100644 --- a/test/loader.spec.js +++ b/test/loader.spec.js @@ -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 {} +` + ) + + }); });