From 827e89cfc47ef93f7cb7f25cb19f42cf33da7548 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Tue, 26 Feb 2019 14:48:42 -0800 Subject: [PATCH] feat(ivy): support inline ', + }) + export class TestCmp {} + `); + + env.driveMain(); + const jsContents = env.getContents('test.js'); + expect(jsContents).toContain('styles: ["h1[_ngcontent-%COMP%] {font-size: larger}"]'); + }); + + it('should process inline tags', () => { + env.tsconfig(); + env.write('style.css', `h1 {font-size: larger}`); + env.write('test.ts', ` + import {Component} from '@angular/core'; + + @Component({ + selector: 'test', + template: '', + }) + export class TestCmp {} + `); + + env.driveMain(); + const jsContents = env.getContents('test.js'); + expect(jsContents).toContain('styles: ["h1[_ngcontent-%COMP%] {font-size: larger}"]'); + }); + }); }); function expectTokenAtPosition( diff --git a/packages/compiler/src/render3/r3_template_transform.ts b/packages/compiler/src/render3/r3_template_transform.ts index c8fd92d270..371dda13b4 100644 --- a/packages/compiler/src/render3/r3_template_transform.ts +++ b/packages/compiler/src/render3/r3_template_transform.ts @@ -47,9 +47,12 @@ const IDENT_EVENT_IDX = 10; const TEMPLATE_ATTR_PREFIX = '*'; // Result of the html AST to Ivy AST transformation -export type Render3ParseResult = { - nodes: t.Node[]; errors: ParseError[]; -}; +export interface Render3ParseResult { + nodes: t.Node[]; + errors: ParseError[]; + styles: string[]; + styleUrls: string[]; +} export function htmlAstToRender3Ast( htmlNodes: html.Node[], bindingParser: BindingParser): Render3ParseResult { @@ -68,28 +71,33 @@ export function htmlAstToRender3Ast( return { nodes: ivyNodes, errors: allErrors, + styleUrls: transformer.styleUrls, + styles: transformer.styles, }; } class HtmlAstToIvyAst implements html.Visitor { errors: ParseError[] = []; + styles: string[] = []; + styleUrls: string[] = []; constructor(private bindingParser: BindingParser) {} // HTML visitor visitElement(element: html.Element): t.Node|null { const preparsedElement = preparseElement(element); - if (preparsedElement.type === PreparsedElementType.SCRIPT || - preparsedElement.type === PreparsedElementType.STYLE) { - // Skipping