Skip to content

Commit

Permalink
Merge pull request #430 from sveltejs/disallow-import-root
Browse files Browse the repository at this point in the history
disallow `import root` during validation
  • Loading branch information
Rich-Harris authored Apr 2, 2017
2 parents 7c5eaa2 + f6934a1 commit 132de5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/validate/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,13 @@ export default function validateJs ( validator, js ) {

validator.defaultExport = node;
}

if ( node.type === 'ImportDeclaration' ) {
node.specifiers.forEach( specifier => {
if ( specifier.local.name === 'root' ) {
validator.error( `Imported identifiers cannot have a name of 'root' due to technical limitations`, specifier.start );
}
});
}
});
}
8 changes: 8 additions & 0 deletions test/validator/samples/import-root/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[{
"message": "Imported identifiers cannot have a name of 'root' due to technical limitations",
"pos": 17,
"loc": {
"line": 2,
"column": 8
}
}]
3 changes: 3 additions & 0 deletions test/validator/samples/import-root/input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<script>
import root from 'foo';
</script>

0 comments on commit 132de5c

Please sign in to comment.