From 931b7f556d90d0efc96492e7f522faa3cded3454 Mon Sep 17 00:00:00 2001 From: Simon Holthausen Date: Tue, 11 Apr 2023 11:08:49 +0200 Subject: [PATCH] cePropsDefinition -> ceProps --- elements/index.d.ts | 2 +- src/compiler/compile/Component.ts | 12 ++++++------ src/compiler/compile/compiler_errors.ts | 6 +++--- src/compiler/compile/render_dom/index.ts | 2 +- .../samples/camel-case-attribute/main.svelte | 2 +- .../samples/ce-options-valid/main.svelte | 2 +- .../samples/reflect-attributes/main.svelte | 2 +- .../samples/reflect-attributes/my-widget.svelte | 5 +---- 8 files changed, 15 insertions(+), 18 deletions(-) diff --git a/elements/index.d.ts b/elements/index.d.ts index fcdeacecf8..b73d027657 100644 --- a/elements/index.d.ts +++ b/elements/index.d.ts @@ -1591,7 +1591,7 @@ export interface SvelteHTMLElements { 'svelte:fragment': { slot?: string }; 'svelte:options': { tag?: string | null | undefined; - cePropsDefinition?: Record | undefined, + ceProps?: Record | undefined, [name: string]: any }; 'svelte:head': { [name: string]: any }; diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 9d42d0e102..d21521a915 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -45,7 +45,7 @@ interface ComponentOptions { immutable?: boolean; accessors?: boolean; preserveWhitespace?: boolean; - cePropsDefinition?: Record; + ceProps?: Record; } const regex_leading_directory_separator = /^[/\\]/; @@ -1574,11 +1574,11 @@ function process_component_options(component: Component, nodes) { break; } - case 'cePropsDefinition': { - const error = () => component.error(attribute, compiler_errors.invalid_cePropsDefinition_attribute); + case 'ceProps': { + const error = () => component.error(attribute, compiler_errors.invalid_ceProps_attribute); const { value } = attribute; const chunk = value[0]; - component_options.cePropsDefinition = {}; + component_options.ceProps = {}; if (!chunk) { break; @@ -1593,7 +1593,7 @@ function process_component_options(component: Component, nodes) { if (property.type !== 'Property' || property.computed || property.key.type !== 'Identifier' || property.value.type !== 'ObjectExpression') { return error(); } - component_options.cePropsDefinition[property.key.name] = {}; + component_options.ceProps[property.key.name] = {}; for (const prop of property.value.properties) { if (prop.type !== 'Property' || prop.computed || prop.key.type !== 'Identifier' || prop.value.type !== 'Literal') { return error(); @@ -1605,7 +1605,7 @@ function process_component_options(component: Component, nodes) { ) { return error(); } - component_options.cePropsDefinition[property.key.name][prop.key.name] = prop.value.value; + component_options.ceProps[property.key.name][prop.key.name] = prop.value.value; } } diff --git a/src/compiler/compile/compiler_errors.ts b/src/compiler/compile/compiler_errors.ts index fb9130f640..c7b8554331 100644 --- a/src/compiler/compile/compiler_errors.ts +++ b/src/compiler/compile/compiler_errors.ts @@ -206,9 +206,9 @@ export default { code: 'invalid-tag-attribute', message: "'tag' must be a string literal" }, - invalid_cePropsDefinition_attribute: { - code: 'invalid-cePropsDefinition-attribute', - message: "'cePropsDefinition' must be a statically analyzable object literal of the form " + + invalid_ceProps_attribute: { + code: 'invalid-ceProps-attribute', + message: "'ceProps' must be a statically analyzable object literal of the form " + "'{ prop: { attribute?: string; type?: 'String' | 'Boolean' | 'Number' | 'Array' | 'Object', reflect?: boolean; } }'" }, invalid_namespace_property: (namespace: string, suggestion?: string) => ({ diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index b4b96ce42e..8a4fd4437d 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -544,7 +544,7 @@ export default function dom( if (options.customElement && component.tag != null) { const props_str = writable_props.reduce((def, prop) => { - def[prop.export_name] = component.component_options.cePropsDefinition?.[prop.export_name] || {}; + def[prop.export_name] = component.component_options.ceProps?.[prop.export_name] || {}; if (prop.is_boolean && !def[prop.export_name].type) { def[prop.export_name].type = 'Boolean'; } diff --git a/test/custom-elements/samples/camel-case-attribute/main.svelte b/test/custom-elements/samples/camel-case-attribute/main.svelte index 0738e51607..bcbc35471c 100644 --- a/test/custom-elements/samples/camel-case-attribute/main.svelte +++ b/test/custom-elements/samples/camel-case-attribute/main.svelte @@ -1,6 +1,6 @@ diff --git a/test/custom-elements/samples/reflect-attributes/main.svelte b/test/custom-elements/samples/reflect-attributes/main.svelte index 59fadcc3c6..a1d3f67fbc 100644 --- a/test/custom-elements/samples/reflect-attributes/main.svelte +++ b/test/custom-elements/samples/reflect-attributes/main.svelte @@ -1,6 +1,6 @@