Merge pull request #1744 from sveltejs/gh-1704

warn on unused helpers
pull/1749/head
Rich Harris 6 years ago committed by GitHub
commit 0d10d6cc2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -260,8 +260,7 @@ export default class Component {
if (this.defaultExport) {
const categories = {
components: 'component',
// TODO helpers require a bit more work — need to analyse all expressions
// helpers: 'helper',
helpers: 'helper',
events: 'event definition',
transitions: 'transition',
actions: 'actions',

@ -115,6 +115,8 @@ export default class Expression {
let object = node;
while (object.type === 'MemberExpression') object = object.object;
component.used.helpers.add(name);
const alias = component.templateVars.get(`helpers-${name}`);
if (alias !== name) code.overwrite(object.start, object.end, alias);
return;

@ -1,15 +1,32 @@
[{
"code": "invalid-callee",
"message": "'foo' is an invalid callee (should be one of this.*, refs.*, event.*, options.*, console.*, set, fire, destroy or bar). 'foo' exists on 'helpers', did you put it in the wrong place?",
"pos": 18,
"start": {
"line": 1,
"column": 18,
"character": 18
[
{
"code": "invalid-callee",
"message": "'foo' is an invalid callee (should be one of this.*, refs.*, event.*, options.*, console.*, set, fire, destroy or bar). 'foo' exists on 'helpers', did you put it in the wrong place?",
"pos": 18,
"start": {
"line": 1,
"column": 18,
"character": 18
},
"end": {
"line": 1,
"column": 23,
"character": 23
}
},
"end": {
"line": 1,
"column": 23,
"character": 23
{
"code": "unused-helper",
"message": "The 'foo' helper is unused",
"start": {
"line": 12,
"column": 3,
"character": 126
},
"end": {
"line": 14,
"column": 4,
"character": 156
},
"pos": 126
}
}]
]

@ -1,8 +0,0 @@
[{
"message": "The 'uppercase' helper is unused",
"start": {
"line": 4,
"column": 3
},
"pos": 43
}]

@ -0,0 +1,15 @@
[{
"code": "unused-helper",
"message": "The 'uppercase' helper is unused",
"start": {
"line": 4,
"column": 3,
"character": 43
},
"end": {
"line": 4,
"column": 34,
"character": 74
},
"pos": 43
}]
Loading…
Cancel
Save