From cfd3b63b9bb87395b9725e676372cc090d3c66d1 Mon Sep 17 00:00:00 2001 From: Tan Li Hau Date: Thu, 24 Oct 2019 11:54:50 +0800 Subject: [PATCH] warn if using svelte:options tag without compile_options.customElement --- src/compiler/compile/Component.ts | 7 +++++++ .../input.svelte | 1 + .../warnings.json | 17 +++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/validator/samples/missing-custom-element-compile-options/input.svelte create mode 100644 test/validator/samples/missing-custom-element-compile-options/warnings.json diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index b22b351da057..e76696c53d92 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -1307,6 +1307,13 @@ function process_component_options(component: Component, nodes) { }); } + if (tag && !component.compile_options.customElement) { + component.warn(attribute, { + code: 'missing-custom-element-compile-options', + message: `tag name is used when compiling the compenent as a custom element. Did you forgot to add "customElement" for compile options?` + }); + } + component_options.tag = tag; break; } diff --git a/test/validator/samples/missing-custom-element-compile-options/input.svelte b/test/validator/samples/missing-custom-element-compile-options/input.svelte new file mode 100644 index 000000000000..94ecce3ef64e --- /dev/null +++ b/test/validator/samples/missing-custom-element-compile-options/input.svelte @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/validator/samples/missing-custom-element-compile-options/warnings.json b/test/validator/samples/missing-custom-element-compile-options/warnings.json new file mode 100644 index 000000000000..a4c52792abf1 --- /dev/null +++ b/test/validator/samples/missing-custom-element-compile-options/warnings.json @@ -0,0 +1,17 @@ +[ + { + "code": "missing-custom-element-compile-options", + "end": { + "character": 36, + "column": 36, + "line": 1 + }, + "message": "tag name is used when compiling the compenent as a custom element. Did you forgot to add \"customElement\" for compile options?", + "pos": 16, + "start": { + "character": 16, + "column": 16, + "line": 1 + } + } +]