tag as top level part 2 (#2773)

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fmt

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* unit tests pass

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* playwright

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* format

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* format

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* more literals gone

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* remove console log

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* remove only

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fix some recast shit

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* last

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Jess Frazelle
2024-06-24 22:39:04 -07:00
committed by GitHub
parent ad5bfa1a29
commit da6cd5cf9f
44 changed files with 720 additions and 536 deletions

View File

@ -11,6 +11,7 @@ import {
Value,
Literal,
VariableDeclaration,
Identifier,
} from 'lang/wasm'
import {
getNodeFromPath,
@ -23,7 +24,11 @@ import {
isNotLiteralArrayOrStatic,
} from 'lang/std/sketchcombos'
import { toolTips, ToolTip } from '../../useStore'
import { createPipeExpression, splitPathAtPipeExpression } from '../modifyAst'
import {
createIdentifier,
createPipeExpression,
splitPathAtPipeExpression,
} from '../modifyAst'
import {
SketchLineHelper,
@ -40,6 +45,7 @@ import {
import {
createLiteral,
createTagDeclarator,
createCallExpression,
createArrayExpression,
createPipeSubstitution,
@ -51,6 +57,7 @@ import {
import { roundOff, getLength, getAngle } from 'lib/utils'
import { err } from 'lib/trap'
import { perpendicularDistance } from 'sketch-helpers'
import { TagDeclarator } from 'wasm-lib/kcl/bindings/TagDeclarator'
export type Coords2d = [number, number]
@ -1406,7 +1413,7 @@ export const angledLineThatIntersects: SketchLineHelper = {
?.value || createLiteral('')
: createLiteral('')
const intersectTagName =
intersectTag.type === 'Literal' ? intersectTag.value : ''
intersectTag.type === 'Identifier' ? intersectTag.name : ''
const nodeMeta2 = getNodeFromPath<VariableDeclaration>(
_node,
pathToNode,
@ -1497,23 +1504,23 @@ export const angledLineThatIntersects: SketchLineHelper = {
)
}
if (intersectTag !== -1) {
const tag = firstArg.properties[intersectTag]?.value
const tag = firstArg.properties[intersectTag]?.value as Identifier
const pathToTagProp: PathToNode = [
...pathToObjectExp,
[intersectTag, 'index'],
['value', 'Property'],
]
returnVal.push(
constrainInfo(
'intersectionTag',
isNotLiteralArrayOrStatic(tag),
code.slice(tag.start, tag.end),
'angledLineThatIntersects',
'intersectTag',
[tag.start, tag.end],
pathToTagProp
)
const info = constrainInfo(
'intersectionTag',
// This will always be a tag identifier.
false,
code.slice(tag.start, tag.end),
'angledLineThatIntersects',
'intersectTag',
[tag.start, tag.end],
pathToTagProp
)
returnVal.push(info)
}
return returnVal
},
@ -1830,17 +1837,18 @@ function addTag(tagIndex = 2): addTagFn {
// Tag is always 3rd expression now, using arg index feels brittle
// but we can come up with a better way to identify tag later.
const thirdArg = primaryCallExp.arguments?.[tagIndex]
const tagLiteral =
thirdArg || (createLiteral(findUniqueName(_node, 'seg', 2)) as Literal)
const tagDeclarator =
thirdArg ||
(createTagDeclarator(findUniqueName(_node, 'seg', 2)) as TagDeclarator)
const isTagExisting = !!thirdArg
if (!isTagExisting) {
primaryCallExp.arguments[tagIndex] = tagLiteral
primaryCallExp.arguments[tagIndex] = tagDeclarator
}
if ('value' in tagLiteral) {
// Now TypeScript knows tagLiteral has a value property
if ('value' in tagDeclarator) {
// Now TypeScript knows tagDeclarator has a value property
return {
modifiedAst: _node,
tag: String(tagLiteral.value),
tag: String(tagDeclarator.value),
}
} else {
return new Error('Unable to assign tag without value')