Skip to content

Commit

Permalink
add identifier creator
Browse files Browse the repository at this point in the history
  • Loading branch information
liady committed Nov 20, 2023
1 parent c5bc115 commit dee71b2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 4 additions & 3 deletions editor/src/components/shared/scoped-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
jsExpressionValue,
jsxConditionalExpressionWithoutUID,
emptyComments,
jsExpressionIdentifier,
} from '../../core/shared/element-template'
import { type VariablesInScope } from '../canvas/ui-jsx-canvas'
import { toComponentId } from '../../core/shared/element-path'
Expand Down Expand Up @@ -113,15 +114,15 @@ function getMatchingElementForVariable(variable: Variable) {
switch (variable.type) {
case 'string':
return jsxElementWithoutUID('span', jsxAttributesFromMap({}), [
jsxTextBlock(`{${variable.name}}`),
jsExpressionIdentifier(variable.name, emptyComments, undefined),
])
case 'number':
return jsxElementWithoutUID('span', jsxAttributesFromMap({}), [
jsxTextBlock(`{${variable.name}}`),
jsExpressionIdentifier(variable.name, emptyComments, undefined),
])
case 'boolean':
return jsxConditionalExpressionWithoutUID(
jsExpressionValue(variable.name, emptyComments, undefined, true),
jsExpressionIdentifier(variable.name, emptyComments, undefined),
variable.name,
jsExpressionValue(null, emptyComments),
jsExpressionValue(null, emptyComments),
Expand Down
16 changes: 14 additions & 2 deletions editor/src/core/shared/element-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,26 @@ export function jsExpressionValue<T>(
value: T,
comments: ParsedComments,
uid: string = UUID(),
identifier: boolean = false,
): JSExpressionValue<T> {
return {
type: 'ATTRIBUTE_VALUE',
value: value,
comments: comments,
uid: uid,
identifier: identifier,
}
}

export function jsExpressionIdentifier<T>(
value: T,
comments: ParsedComments,
uid: string = UUID(),
): JSExpressionValue<T> {
return {
type: 'ATTRIBUTE_VALUE',
value: value,
comments: comments,
uid: uid,
identifier: true,
}
}

Expand Down

0 comments on commit dee71b2

Please sign in to comment.