From 3fdfdb4089b62d0b02002cbc74fb0c5c19c4a003 Mon Sep 17 00:00:00 2001 From: Nguyen Tran Date: Fri, 24 Mar 2023 01:38:00 -0400 Subject: [PATCH] Use existing simpler method to resolve collisions --- src/compiler/compile/nodes/shared/Context.ts | 2 +- .../compile/render_dom/wrappers/AwaitBlock.ts | 3 --- .../compile/render_dom/wrappers/EachBlock.ts | 3 --- .../compile/utils/resolve_computed_props.ts | 19 ------------------- 4 files changed, 1 insertion(+), 26 deletions(-) delete mode 100644 src/compiler/compile/utils/resolve_computed_props.ts diff --git a/src/compiler/compile/nodes/shared/Context.ts b/src/compiler/compile/nodes/shared/Context.ts index 560b0a97ab..76ac895681 100644 --- a/src/compiler/compile/nodes/shared/Context.ts +++ b/src/compiler/compile/nodes/shared/Context.ts @@ -127,7 +127,7 @@ export function unpack_destructuring({ if (property.computed) { // e.g { [computedProperty]: ... } - const property_name = x`computed_property` as Identifier; + const property_name = component.get_unique_name('computed_property'); contexts.push({ type: 'ComputedProperty', diff --git a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts index aa5d3ad774..534595f4a9 100644 --- a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts @@ -12,7 +12,6 @@ import { Context } from '../../nodes/shared/Context'; import { Identifier, Literal, Node } from 'estree'; import { add_const_tags, add_const_tags_context } from './shared/add_const_tags'; import Expression from '../../nodes/shared/Expression'; -import { resolve_computed_prop_conflicts } from '../../utils/resolve_computed_props'; type Status = 'pending' | 'then' | 'catch'; @@ -99,8 +98,6 @@ class AwaitBlockBranch extends Wrapper { } render_get_context() { - resolve_computed_prop_conflicts(this.block, this.is_destructured ? this.value_contexts : [], this.has_consts(this.node) ? this.node.const_tags : []); - const props = this.is_destructured ? this.value_contexts.map(prop => { if (prop.type === 'ComputedProperty') { const expression = new Expression(this.renderer.component, this.node, this.has_consts(this.node) ? this.node.scope : null, prop.key); diff --git a/src/compiler/compile/render_dom/wrappers/EachBlock.ts b/src/compiler/compile/render_dom/wrappers/EachBlock.ts index b37bee08f7..9c1af7ce44 100644 --- a/src/compiler/compile/render_dom/wrappers/EachBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/EachBlock.ts @@ -10,7 +10,6 @@ import { Identifier, Node } from 'estree'; import get_object from '../../utils/get_object'; import { add_const_tags, add_const_tags_context } from './shared/add_const_tags'; import Expression from '../../nodes/shared/Expression'; -import { resolve_computed_prop_conflicts } from '../../utils/resolve_computed_props'; export class ElseBlockWrapper extends Wrapper { node: ElseBlock; @@ -365,8 +364,6 @@ export default class EachBlockWrapper extends Wrapper { this.else.fragment.render(this.else.block, null, x`#nodes` as Identifier); } - resolve_computed_prop_conflicts(this.block, this.node.contexts, this.node.const_tags); - this.context_props = this.node.contexts.map(prop => { if (prop.type === 'DestructuredVariable') { const to_ctx = (name: string) => renderer.context_lookup.has(name) ? x`child_ctx[${renderer.context_lookup.get(name).index}]` : { type: 'Identifier', name } as Node; diff --git a/src/compiler/compile/utils/resolve_computed_props.ts b/src/compiler/compile/utils/resolve_computed_props.ts deleted file mode 100644 index a6725dfe92..0000000000 --- a/src/compiler/compile/utils/resolve_computed_props.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { Context } from '../nodes/shared/Context'; -import ConstTag from '../nodes/ConstTag'; -import Block from '../render_dom/Block'; - -export function resolve_computed_prop_conflicts(block: Block, node_contexts: Context[], node_const_tags: ConstTag[]) { - node_contexts.forEach((context: Context) => { - if (context.type === 'ComputedProperty') { - context.property_name.name = block.get_unique_name('computed_prop').name; - } - }); - - node_const_tags.forEach((const_tag: ConstTag) => { - const_tag.contexts.forEach((context: Context) => { - if (context.type === 'ComputedProperty') { - context.property_name.name = block.get_unique_name('computed_prop').name; - } - }); - }); -}