From 23f8f4ba6d769f65da7b9dd1308f65d218300e36 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Wed, 14 Jul 2021 01:33:55 +0800 Subject: [PATCH] [feat] centralise parse errors (#6519) Co-authored-by: pngwn --- src/compiler/parse/errors.ts | 192 ++++++++++++++++++ src/compiler/parse/index.ts | 27 +-- src/compiler/parse/read/context.ts | 17 +- src/compiler/parse/read/expression.ts | 6 +- src/compiler/parse/read/script.ts | 19 +- src/compiler/parse/read/style.ts | 29 +-- src/compiler/parse/state/mustache.ts | 71 +++---- src/compiler/parse/state/tag.ts | 104 +++------- .../samples/error-comment-unclosed/error.json | 2 +- 9 files changed, 277 insertions(+), 190 deletions(-) create mode 100644 src/compiler/parse/errors.ts diff --git a/src/compiler/parse/errors.ts b/src/compiler/parse/errors.ts new file mode 100644 index 0000000000..b563b7572a --- /dev/null +++ b/src/compiler/parse/errors.ts @@ -0,0 +1,192 @@ +// All parser errors should be listed and accessed from here + +import list from '../utils/list'; + +/** + * @internal + */ +export default { + css_syntax_error: (message) => ({ + code: 'css-syntax-error', + message + }), + duplicate_attribute: { + code: 'duplicate-attribute', + message: 'Attributes need to be unique' + }, + duplicate_element: (slug: string, name: string) => ({ + code: `duplicate-${slug}`, + message: `A component can only have one <${name}> tag` + }), + duplicate_style: { + code: 'duplicate-style', + message: 'You can only have one top-level