Skip to content

Commit

Permalink
[chore] improve illegal declaration error message
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Sep 11, 2021
1 parent c040f13 commit f64259c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ export default class Component {

scope.declarations.forEach((node, name) => {
if (name[0] === '$') {
return this.error(node as any, compiler_errors.illegal_declaration);
return this.error(node as any, compiler_errors.illegal_declaration(name));
}

const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
Expand Down Expand Up @@ -660,7 +660,7 @@ export default class Component {

instance_scope.declarations.forEach((node, name) => {
if (name[0] === '$') {
return this.error(node as any, compiler_errors.illegal_declaration);
return this.error(node as any, compiler_errors.illegal_declaration(name));
}

const writable = node.type === 'VariableDeclaration' && (node.kind === 'var' || node.kind === 'let');
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/compile/compiler_errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ export default {
code: 'default-export',
message: 'A component cannot have a default export'
},
illegal_declaration: {
illegal_declaration: (name: string) => ({
code: 'illegal-declaration',
message: 'The $ prefix is reserved, and cannot be used for variable and import names'
},
message: `The $ prefix is reserved, and cannot be used for variable and import names, but found ${name}`
}),
illegal_subscription: {
code: 'illegal-subscription',
message: 'Cannot reference store value inside <script context="module">'
Expand Down

0 comments on commit f64259c

Please sign in to comment.