From f6934a1d20e1e30e1466f2ae3acb377d40091971 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 31 Mar 2017 08:20:37 -0400 Subject: [PATCH] disallow `import root` during validation --- src/validate/js/index.js | 8 ++++++++ test/validator/samples/import-root/errors.json | 8 ++++++++ test/validator/samples/import-root/input.html | 3 +++ 3 files changed, 19 insertions(+) create mode 100644 test/validator/samples/import-root/errors.json create mode 100644 test/validator/samples/import-root/input.html diff --git a/src/validate/js/index.js b/src/validate/js/index.js index 0e6d0488f1..cdef266c96 100644 --- a/src/validate/js/index.js +++ b/src/validate/js/index.js @@ -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 ); + } + }); + } }); } diff --git a/test/validator/samples/import-root/errors.json b/test/validator/samples/import-root/errors.json new file mode 100644 index 0000000000..ec9384b0c8 --- /dev/null +++ b/test/validator/samples/import-root/errors.json @@ -0,0 +1,8 @@ +[{ + "message": "Imported identifiers cannot have a name of 'root' due to technical limitations", + "pos": 17, + "loc": { + "line": 2, + "column": 8 + } +}] diff --git a/test/validator/samples/import-root/input.html b/test/validator/samples/import-root/input.html new file mode 100644 index 0000000000..d1cda13562 --- /dev/null +++ b/test/validator/samples/import-root/input.html @@ -0,0 +1,3 @@ +