diff --git a/src/Stats.ts b/src/Stats.ts index 7994d9b048..5f8c7d4f94 100644 --- a/src/Stats.ts +++ b/src/Stats.ts @@ -1,4 +1,5 @@ import { Node } from './interfaces'; +import Generator from './generators/Generator'; const now = (typeof process !== 'undefined' && process.hrtime) ? () => { @@ -63,31 +64,36 @@ export default class Stats { this.currentChildren = this.currentTiming ? this.currentTiming.children : this.timings; } - render({ imports }: { - imports: Node[] - }) { + render(generator: Generator) { const timings = Object.assign({ total: now() - this.startTime }, collapseTimings(this.timings)); + const imports = generator.imports.map(node => { + return { + source: node.source.value, + specifiers: node.specifiers.map(specifier => { + return { + name: ( + specifier.type === 'ImportDefaultSpecifier' ? 'default' : + specifier.type === 'ImportNamespaceSpecifier' ? '*' : + specifier.imported.name + ), + as: specifier.local.name + }; + }) + } + }); + + const hooks: Record = {}; + if (generator.templateProperties.oncreate) hooks.oncreate = true; + if (generator.templateProperties.ondestroy) hooks.ondestroy = true; + return { timings, warnings: [], // TODO - imports: imports.map(node => { - return { - source: node.source.value, - specifiers: node.specifiers.map(specifier => { - return { - name: ( - specifier.type === 'ImportDefaultSpecifier' ? 'default' : - specifier.type === 'ImportNamespaceSpecifier' ? '*' : - specifier.imported.name - ), - as: specifier.local.name - }; - }) - } - }) + imports, + hooks }; } } \ No newline at end of file diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index cf423739d4..250255ef98 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -385,9 +385,7 @@ export default class Generator { ast: this.ast, js, css, - stats: this.stats.render({ - imports: this.imports - }), + stats: this.stats.render(this), // TODO deprecate code: js.code, diff --git a/test/stats/samples/hooks/_config.js b/test/stats/samples/hooks/_config.js new file mode 100644 index 0000000000..78fc771a06 --- /dev/null +++ b/test/stats/samples/hooks/_config.js @@ -0,0 +1,7 @@ +export default { + test(assert, stats) { + assert.deepEqual(stats.hooks, { + oncreate: true + }); + } +}; \ No newline at end of file diff --git a/test/stats/samples/hooks/input.html b/test/stats/samples/hooks/input.html new file mode 100644 index 0000000000..fde68977b2 --- /dev/null +++ b/test/stats/samples/hooks/input.html @@ -0,0 +1,7 @@ + \ No newline at end of file