Skip to content

Commit 5a84041

Browse files
alexkpekmgechev
authored andcommittedJul 3, 2018
fix: url not passed to transformStyle when using styleUrls (#686)
1 parent 5e067a1 commit 5a84041

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed
 

‎src/angular/metadataReader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export class MetadataReader {
125125
) =>
126126
this._resolve(url).fmap<StyleMetadata>(style => ({
127127
node: undefined,
128-
style: normalizeTransformed(Config.transformStyle(style!)),
128+
style: normalizeTransformed(Config.transformStyle(style!, url)),
129129
url
130130
}))
131131
)

‎test/angular/metadataReader.spec.ts

+41
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,47 @@ describe('metadataReader', () => {
272272
}
273273
});
274274

275+
it('should pass url to Config.transformStyle when using styleUrls', () => {
276+
let styleUrl = 'test.scss';
277+
let invoked = false;
278+
const bak = Config.transformStyle;
279+
280+
try {
281+
Config.transformStyle = (code, url) => {
282+
invoked = true;
283+
expect(url).to.be.an('string');
284+
expect(url!.endsWith('.scss')).eq(true);
285+
return { code };
286+
};
287+
288+
const code = `
289+
@Component({
290+
selector: 'foo',
291+
moduleId: module.id,
292+
templateUrl: 'foo.html',
293+
styleUrls: ['${styleUrl}']
294+
})
295+
class Bar {}
296+
`;
297+
298+
const reader = new MetadataReader(new FsFileResolver());
299+
const ast = getAst(code, __dirname + '/../../test/fixtures/metadataReader/moduleid/foo.ts');
300+
const classDeclaration = <ts.ClassDeclaration>last(ast.statements);
301+
expect(invoked).eq(false);
302+
const metadata = reader.read(classDeclaration)!;
303+
expect(metadata instanceof ComponentMetadata).eq(true);
304+
expect(metadata.selector).eq('foo');
305+
const m = <ComponentMetadata>metadata;
306+
expect(m.template!.template.code.trim()).eq('<div></div>');
307+
expect(m.template!.url!.endsWith('foo.html')).eq(true);
308+
expect(m.styles![0]!.style.code).eq('');
309+
expect(m.styles![0]!.url).to.be.an('string');
310+
expect(invoked).eq(true);
311+
} finally {
312+
Config.transformStyle = bak;
313+
}
314+
});
315+
275316
it('should work work with templates with "`"', () => {
276317
const code = `
277318
@Component({

‎test/fixtures/metadataReader/moduleid/test.scss

Whitespace-only changes.

0 commit comments

Comments
 (0)
Please sign in to comment.