Lint and format src/compiler/compile/render_dom/wrappers/Document.js

pull/8569/head
Simon Holthausen 3 years ago
parent c7b18cca0d
commit 10d178e190

@ -11,7 +11,6 @@ const readonly = new Set(['fullscreenElement', 'visibilityState']);
/** @extends Wrapper */ /** @extends Wrapper */
export default class DocumentWrapper extends Wrapper { export default class DocumentWrapper extends Wrapper {
/** @type {import('../../nodes/Document.js').default} */ /** @type {import('../../nodes/Document.js').default} */
node; node;
@ -43,11 +42,12 @@ export default class DocumentWrapper extends Wrapper {
/** @type {Record<string, string>} */ /** @type {Record<string, string>} */
const bindings = {}; const bindings = {};
add_event_handlers(block, x `@_document`, this.handlers); add_event_handlers(block, x`@_document`, this.handlers);
add_actions(block, x `@_document`, this.node.actions); add_actions(block, x`@_document`, this.node.actions);
this.node.bindings.forEach((binding) => { this.node.bindings.forEach((binding) => {
// TODO: what if it's a MemberExpression? // TODO: what if it's a MemberExpression?
const binding_name = ( /** @type {import('estree').Identifier} */(binding.expression.node)).name; const binding_name = /** @type {import('estree').Identifier} */ (binding.expression.node)
.name;
// in dev mode, throw if read-only values are written to // in dev mode, throw if read-only values are written to
if (readonly.has(binding.name)) { if (readonly.has(binding.name)) {
renderer.readonly.add(binding_name); renderer.readonly.add(binding_name);
@ -56,8 +56,7 @@ export default class DocumentWrapper extends Wrapper {
const binding_events = associated_events[binding.name]; const binding_events = associated_events[binding.name];
const property = binding.name; const property = binding.name;
binding_events.forEach((associated_event) => { binding_events.forEach((associated_event) => {
if (!events[associated_event]) if (!events[associated_event]) events[associated_event] = [];
events[associated_event] = [];
events[associated_event].push({ events[associated_event].push({
name: binding_name, name: binding_name,
value: property value: property
@ -70,24 +69,20 @@ export default class DocumentWrapper extends Wrapper {
renderer.add_to_context(id.name); renderer.add_to_context(id.name);
const fn = renderer.reference(id.name); const fn = renderer.reference(id.name);
props.forEach((prop) => { props.forEach((prop) => {
renderer.meta_bindings.push(b `this._state.${prop.name} = @_document.${prop.value};`); renderer.meta_bindings.push(b`this._state.${prop.name} = @_document.${prop.value};`);
}); });
block.event_listeners.push(x ` block.event_listeners.push(x`
@listen(@_document, "${event}", ${fn}) @listen(@_document, "${event}", ${fn})
`); `);
component.partly_hoisted.push(b ` component.partly_hoisted.push(b`
function ${id}() { function ${id}() {
${props.map((prop) => renderer.invalidate(prop.name, x `${prop.name} = @_document.${prop.value}`))} ${props.map((prop) => renderer.invalidate(prop.name, x`${prop.name} = @_document.${prop.value}`))}
} }
`); `);
block.chunks.init.push(b ` block.chunks.init.push(b`
@add_render_callback(${fn}); @add_render_callback(${fn});
`); `);
component.has_reactive_assignments = true; component.has_reactive_assignments = true;
}); });
} }
} }

Loading…
Cancel
Save