Rename function since it's a type assertion, not cast
This commit is contained in:
@ -62,7 +62,7 @@ import {
|
||||
editorManager,
|
||||
} from 'lib/singletons'
|
||||
import {
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
expectNodeOnPath,
|
||||
getNodeFromPath,
|
||||
getNodePathFromSourceRange,
|
||||
@ -480,7 +480,7 @@ export class SceneEntities {
|
||||
'CallExpression'
|
||||
)
|
||||
if (err(callExp)) return
|
||||
const callExpName = castDynamicNode<CallExpression>(
|
||||
const callExpName = isNodeType<CallExpression>(
|
||||
callExp.node,
|
||||
'CallExpression'
|
||||
)
|
||||
@ -606,7 +606,7 @@ export class SceneEntities {
|
||||
'VariableDeclaration'
|
||||
)
|
||||
if (trap(_node1)) return Promise.reject(_node1)
|
||||
const variableDeclarationName = castDynamicNode<VariableDeclaration>(
|
||||
const variableDeclarationName = isNodeType<VariableDeclaration>(
|
||||
_node1.node,
|
||||
'VariableDeclaration'
|
||||
)
|
||||
@ -794,7 +794,7 @@ export class SceneEntities {
|
||||
'VariableDeclaration'
|
||||
)
|
||||
if (trap(_node)) return Promise.reject(_node)
|
||||
const sketchInit = castDynamicNode<VariableDeclaration>(
|
||||
const sketchInit = isNodeType<VariableDeclaration>(
|
||||
_node.node,
|
||||
'VariableDeclaration'
|
||||
)
|
||||
@ -847,7 +847,7 @@ export class SceneEntities {
|
||||
'VariableDeclaration'
|
||||
)
|
||||
if (trap(_node)) return Promise.reject(_node)
|
||||
const sketchInit = castDynamicNode<VariableDeclaration>(
|
||||
const sketchInit = isNodeType<VariableDeclaration>(
|
||||
_node.node,
|
||||
'VariableDeclaration'
|
||||
)
|
||||
@ -1829,7 +1829,7 @@ function prepareTruncatedMemoryAndAst(
|
||||
if (err(_node)) return _node
|
||||
if (isArray(_node.node))
|
||||
return new Error('Expected node to be an object, but found Array')
|
||||
const variableDeclarationName = castDynamicNode<VariableDeclaration>(
|
||||
const variableDeclarationName = isNodeType<VariableDeclaration>(
|
||||
_node.node,
|
||||
'VariableDeclaration'
|
||||
)
|
||||
@ -1959,10 +1959,7 @@ export function sketchGroupFromPathToNode({
|
||||
const varDec = _varDec.node
|
||||
if (isArray(varDec))
|
||||
return new Error('Expected node to be an object, but found Array')
|
||||
const varName = castDynamicNode<VariableDeclarator>(
|
||||
varDec,
|
||||
'VariableDeclarator'
|
||||
)
|
||||
const varName = isNodeType<VariableDeclarator>(varDec, 'VariableDeclarator')
|
||||
? varDec.id.name
|
||||
: ''
|
||||
const result = programMemory.get(varName)
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
getNodePathFromSourceRange,
|
||||
getLastNodeFromPath,
|
||||
DynamicNode,
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
expectNodeOnPath,
|
||||
} from '../../lang/queryAst'
|
||||
import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints'
|
||||
@ -68,7 +68,7 @@ export function equalAngleInfo({
|
||||
)
|
||||
const isAllTooltips = nodes.every(
|
||||
(node) =>
|
||||
castDynamicNode<CallExpression>(node, 'CallExpression') &&
|
||||
isNodeType<CallExpression>(node, 'CallExpression') &&
|
||||
toolTips.includes(node.callee.name as any)
|
||||
)
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
getNodePathFromSourceRange,
|
||||
getLastNodeFromPath,
|
||||
DynamicNode,
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
expectNodeOnPath,
|
||||
} from '../../lang/queryAst'
|
||||
import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints'
|
||||
@ -68,7 +68,7 @@ export function setEqualLengthInfo({
|
||||
)
|
||||
const isAllTooltips = nodes.every(
|
||||
(node) =>
|
||||
castDynamicNode<CallExpression>(node, 'CallExpression') &&
|
||||
isNodeType<CallExpression>(node, 'CallExpression') &&
|
||||
toolTips.includes(node.callee.name as any)
|
||||
)
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
getNodePathFromSourceRange,
|
||||
getLastNodeFromPath,
|
||||
DynamicNode,
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
} from '../../lang/queryAst'
|
||||
import {
|
||||
PathToNodeMap,
|
||||
@ -45,7 +45,7 @@ export function horzVertInfo(
|
||||
|
||||
const isAllTooltips = nodes.every(
|
||||
(node) =>
|
||||
castDynamicNode<CallExpression>(node, 'CallExpression') &&
|
||||
isNodeType<CallExpression>(node, 'CallExpression') &&
|
||||
toolTips.includes(node.callee.name as any)
|
||||
)
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import {
|
||||
getLastNodeFromPath,
|
||||
expectNodeOnPath,
|
||||
DynamicNode,
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
} from '../../lang/queryAst'
|
||||
import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints'
|
||||
import {
|
||||
@ -116,7 +116,7 @@ export function intersectInfo({
|
||||
)
|
||||
const isAllTooltips = nodes.every(
|
||||
(node) =>
|
||||
castDynamicNode<CallExpression>(node, 'CallExpression') &&
|
||||
isNodeType<CallExpression>(node, 'CallExpression') &&
|
||||
[
|
||||
...toolTips,
|
||||
'startSketchAt', // TODO probably a better place for this to live
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
getNodePathFromSourceRange,
|
||||
getLastNodeFromPath,
|
||||
DynamicNode,
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
} from '../../lang/queryAst'
|
||||
import {
|
||||
PathToNodeMap,
|
||||
@ -62,7 +62,7 @@ export function removeConstrainingValuesInfo({
|
||||
: selectionRanges
|
||||
const isAllTooltips = nodes.every(
|
||||
(node) =>
|
||||
castDynamicNode<CallExpression>(node, 'CallExpression') &&
|
||||
isNodeType<CallExpression>(node, 'CallExpression') &&
|
||||
toolTips.includes(node.callee.name as any)
|
||||
)
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ import {
|
||||
getLastNodeFromPath,
|
||||
DynamicNode,
|
||||
expectNodeOnPath,
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
} from '../../lang/queryAst'
|
||||
import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints'
|
||||
import {
|
||||
@ -79,7 +79,7 @@ export function angleBetweenInfo({
|
||||
)
|
||||
const isAllTooltips = nodes.every(
|
||||
(node) =>
|
||||
castDynamicNode<CallExpression>(node, 'CallExpression') &&
|
||||
isNodeType<CallExpression>(node, 'CallExpression') &&
|
||||
toolTips.includes(node.callee.name as any)
|
||||
)
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import {
|
||||
getNodePathFromSourceRange,
|
||||
getLastNodeFromPath,
|
||||
expectNodeOnPath,
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
} from '../../lang/queryAst'
|
||||
import { isSketchVariablesLinked } from '../../lang/std/sketchConstraints'
|
||||
import {
|
||||
@ -77,7 +77,7 @@ export function horzVertDistanceInfo({
|
||||
)
|
||||
const isAllTooltips = nodes.every(
|
||||
(node) =>
|
||||
castDynamicNode<CallExpression>(node, 'CallExpression') &&
|
||||
isNodeType<CallExpression>(node, 'CallExpression') &&
|
||||
[
|
||||
...toolTips,
|
||||
'startSketchAt', // TODO probably a better place for this to live
|
||||
|
||||
@ -47,7 +47,7 @@ function isAstNode(
|
||||
* Given T and its corresponding SyntaxType, narrow the node to type T if
|
||||
* node.type matches.
|
||||
*/
|
||||
export function castDynamicNode<T extends DynamicNode>(
|
||||
export function isNodeType<T extends DynamicNode>(
|
||||
node: any,
|
||||
syntaxType: SyntaxType | SyntaxType[]
|
||||
): node is T {
|
||||
@ -117,7 +117,7 @@ export function getNodeFromPath<T extends DynamicNode>(
|
||||
if (!stopAtNode) {
|
||||
pathsExplored.push(pathItem)
|
||||
}
|
||||
if (stopAt && castDynamicNode<T>(currentNode, stopAt)) {
|
||||
if (stopAt && isNodeType<T>(currentNode, stopAt)) {
|
||||
// it will match the deepest node of the type
|
||||
// instead of returning at the first match
|
||||
stopAtNode = currentNode
|
||||
@ -169,7 +169,7 @@ export function expectLastNodeFromPath<T extends DynamicNode>(
|
||||
): T | Error {
|
||||
const result = getLastNodeFromPath(node, path)
|
||||
if (err(result)) return result
|
||||
if (!castDynamicNode<T>(result.node, syntaxType)) {
|
||||
if (!isNodeType<T>(result.node, syntaxType)) {
|
||||
return new Error(
|
||||
`Expected node of type ${syntaxType}: found ${JSON.stringify(result)}`
|
||||
)
|
||||
|
||||
@ -14,7 +14,7 @@ import {
|
||||
Identifier,
|
||||
} from 'lang/wasm'
|
||||
import {
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
expectLastNodeFromPath,
|
||||
expectNodeOnPath,
|
||||
getNodeFromPath,
|
||||
@ -1670,7 +1670,7 @@ export function changeSketchArguments(
|
||||
if (isArray(callExpression)) {
|
||||
return new Error('Expected call expression but found array')
|
||||
}
|
||||
if (!castDynamicNode<CallExpression>(callExpression, 'CallExpression')) {
|
||||
if (!isNodeType<CallExpression>(callExpression, 'CallExpression')) {
|
||||
return new Error('Call expression not found')
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import {
|
||||
ProgramMemory,
|
||||
} from '../wasm'
|
||||
import {
|
||||
castDynamicNode,
|
||||
isNodeType,
|
||||
expectNodeOnPath,
|
||||
getLastNodeFromPath,
|
||||
getNodeFromPath,
|
||||
@ -1462,7 +1462,7 @@ export function getRemoveConstraintsTransforms(
|
||||
console.error('Expected node, but found Array')
|
||||
return false
|
||||
}
|
||||
if (castDynamicNode<CallExpression>(node, 'CallExpression'))
|
||||
if (isNodeType<CallExpression>(node, 'CallExpression'))
|
||||
return getRemoveConstraintsTransform(node, constraintType)
|
||||
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user