Skip to content

Commit

Permalink
fix: url not passed to transformStyle when using styleUrls (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkpek authored and mgechev committed Jul 3, 2018
1 parent 5e067a1 commit 5a84041
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/angular/metadataReader.ts
Expand Up @@ -125,7 +125,7 @@ export class MetadataReader {
) =>
this._resolve(url).fmap<StyleMetadata>(style => ({
node: undefined,
style: normalizeTransformed(Config.transformStyle(style!)),
style: normalizeTransformed(Config.transformStyle(style!, url)),
url
}))
)
Expand Down
41 changes: 41 additions & 0 deletions test/angular/metadataReader.spec.ts
Expand Up @@ -272,6 +272,47 @@ describe('metadataReader', () => {
}
});

it('should pass url to Config.transformStyle when using styleUrls', () => {
let styleUrl = 'test.scss';
let invoked = false;
const bak = Config.transformStyle;

try {
Config.transformStyle = (code, url) => {
invoked = true;
expect(url).to.be.an('string');
expect(url!.endsWith('.scss')).eq(true);
return { code };
};

const code = `
@Component({
selector: 'foo',
moduleId: module.id,
templateUrl: 'foo.html',
styleUrls: ['${styleUrl}']
})
class Bar {}
`;

const reader = new MetadataReader(new FsFileResolver());
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/moduleid/foo.ts');
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
expect(invoked).eq(false);
const metadata = reader.read(classDeclaration)!;
expect(metadata instanceof ComponentMetadata).eq(true);
expect(metadata.selector).eq('foo');
const m = <ComponentMetadata>metadata;
expect(m.template!.template.code.trim()).eq('<div></div>');
expect(m.template!.url!.endsWith('foo.html')).eq(true);
expect(m.styles![0]!.style.code).eq('');
expect(m.styles![0]!.url).to.be.an('string');
expect(invoked).eq(true);
} finally {
Config.transformStyle = bak;
}
});

it('should work work with templates with "`"', () => {
const code = `
@Component({
Expand Down
Empty file.

0 comments on commit 5a84041

Please sign in to comment.