Throw an error if using export outside of module

This commit is contained in:
Jakub Žádník 2021-09-28 21:12:46 +03:00
parent 93521da9d8
commit 3cbf99053f
2 changed files with 12 additions and 0 deletions

View File

@ -57,6 +57,14 @@ pub enum ParseError {
#[diagnostic(code(nu::parser::expected_keyword), url(docsrs))]
ExpectedKeyword(String, #[label("expected {0}")] Span),
#[error("Unexpected keyword.")]
#[diagnostic(
code(nu::parser::unexpected_keyword),
url(docsrs),
help("'export' keyword is allowed only in a module.")
)]
UnexpectedKeyword(String, #[label("unexpected {0}")] Span),
#[error("Multiple rest params.")]
#[diagnostic(code(nu::parser::multiple_rest_params), url(docsrs))]
MultipleRestParams(#[label = "multiple rest params"] Span),

View File

@ -2585,6 +2585,10 @@ pub fn parse_statement(
b"alias" => parse_alias(working_set, spans),
b"module" => parse_module(working_set, spans),
b"use" => parse_use(working_set, spans),
b"export" => (
garbage_statement(spans),
Some(ParseError::UnexpectedKeyword("export".into(), spans[0])),
),
_ => {
let (expr, err) = parse_expression(working_set, spans);
(Statement::Pipeline(Pipeline::from_vec(vec![expr])), err)