augment warnings to help people figure out they need to add a <script>

pull/2230/head
Richard Harris 7 years ago
parent a093546def
commit 34c4f79998

@ -1143,9 +1143,12 @@ export default class Component {
if (template_scope && template_scope.names.has(name)) return; if (template_scope && template_scope.names.has(name)) return;
if (globalWhitelist.has(name)) return; if (globalWhitelist.has(name)) return;
let message = `'${name}' is not defined`;
if (!this.ast.instance) message += `. Consider adding a <script> block with 'export let ${name}' to declare a prop`;
this.warn(node, { this.warn(node, {
code: 'missing-declaration', code: 'missing-declaration',
message: `'${name}' is not defined` message
}); });
} }
} }

@ -1,6 +1,6 @@
[{ [{
"code": "missing-declaration", "code": "missing-declaration",
"message": "'whatever' is not defined", "message": "'whatever' is not defined. Consider adding a <script> block with 'export let whatever' to declare a prop",
"pos": 5, "pos": 5,
"start": { "start": {
"line": 1, "line": 1,

@ -1,6 +1,6 @@
[{ [{
"code": "missing-declaration", "code": "missing-declaration",
"message": "'Widget' is not defined", "message": "'Widget' is not defined. Consider adding a <script> block with 'export let Widget' to declare a prop",
"start": { "start": {
"line": 2, "line": 2,
"column": 1, "column": 1,

@ -1,6 +1,6 @@
[{ [{
"code": "missing-declaration", "code": "missing-declaration",
"message": "'foo' is not defined", "message": "'foo' is not defined. Consider adding a <script> block with 'export let foo' to declare a prop",
"start": { "start": {
"line": 1, "line": 1,
"column": 5, "column": 5,

Loading…
Cancel
Save