@@ -7,6 +7,7 @@ import { CompileOptions, Warning } from '../interfaces';
77import Component from './Component' ;
88import fuzzymatch from '../utils/fuzzymatch' ;
99import get_name_from_filename from './utils/get_name_from_filename' ;
10+ import optimise from '../parse/optimise/index' ;
1011
1112const valid_options = [
1213 'format' ,
@@ -25,7 +26,8 @@ const valid_options = [
2526 'tag' ,
2627 'css' ,
2728 'preserveComments' ,
28- 'preserveWhitespace'
29+ 'preserveWhitespace' ,
30+ 'optimiseAst' ,
2931] ;
3032
3133function validate_options ( options : CompileOptions , warnings : Warning [ ] ) {
@@ -57,7 +59,7 @@ function validate_options(options: CompileOptions, warnings: Warning[]) {
5759}
5860
5961export default function compile ( source : string , options : CompileOptions = { } ) {
60- options = assign ( { generate : 'dom' , dev : false } , options ) ;
62+ options = assign ( { generate : 'dom' , dev : false , optimiseAst : true } , options ) ;
6163
6264 const stats = new Stats ( ) ;
6365 const warnings = [ ] ;
@@ -68,6 +70,12 @@ export default function compile(source: string, options: CompileOptions = {}) {
6870 const ast = parse ( source , options ) ;
6971 stats . stop ( 'parse' ) ;
7072
73+ if ( options . optimiseAst ) {
74+ stats . start ( 'optimise-ast' ) ;
75+ optimise ( ast ) ;
76+ stats . stop ( 'optimise-ast' ) ;
77+ }
78+
7179 stats . start ( 'create component' ) ;
7280 const component = new Component (
7381 ast ,
@@ -79,9 +87,10 @@ export default function compile(source: string, options: CompileOptions = {}) {
7987 ) ;
8088 stats . stop ( 'create component' ) ;
8189
82- const js = options . generate === false
83- ? null
84- : options . generate === 'ssr'
90+ const js =
91+ options . generate === false
92+ ? null
93+ : options . generate === 'ssr'
8594 ? render_ssr ( component , options )
8695 : render_dom ( component , options ) ;
8796
0 commit comments