Skip to content

Commit

Permalink
Merge pull request #1838 from sveltejs/gh-1837
Browse files Browse the repository at this point in the history
expose stats.props
  • Loading branch information
Rich-Harris authored Nov 4, 2018
2 parents 1f79099 + 998d86a commit b6efae9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ export default class Stats {
onupdate: !!component.templateProperties.onupdate
};

const computed = new Set(component.computations.map(c => c.key));

return {
props: Array.from(component.expectedProperties).filter(key => !computed.has(key)),
timings,
warnings: this.warnings,
imports,
Expand Down
2 changes: 1 addition & 1 deletion src/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export default function compile(source: string, options: CompileOptions = {}) {
stats.stop('create component');

if (options.generate === false) {
return { ast, stats: stats.render(null), js: null, css: null };
return { ast, stats: stats.render(component), js: null, css: null };
}

if (options.generate === 'ssr') {
Expand Down
5 changes: 5 additions & 0 deletions test/stats/samples/props/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
test(assert, stats) {
assert.deepEqual(stats.props.sort(), ['cats', 'foo', 'name']);
}
};
23 changes: 23 additions & 0 deletions test/stats/samples/props/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h1>Hello {name}!</h1>

<ul>
{#each cats as cat}
<li><a target="_blank" href={cat.video}>{cat.name}</a></li>
{/each}
</ul>

<p>bar: {bar}</p>

<script>
export default {
data() {
return {
name: 'world'
};
},

computed: {
bar: ({ foo }) => foo * 2
}
};
</script>

0 comments on commit b6efae9

Please sign in to comment.