Skip to content

Commit

Permalink
disallow import root during validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry committed Mar 31, 2017
1 parent 38ee4f1 commit f6934a1
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 f6934a1

Please sign in to comment.