Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 6 additions & 26 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"@next/swc-linux-x64-gnu": "16.4.5"
},
"devDependencies": {
"@babel/parser": "8.1.2",
"@babel/parser": "7.29.9",
"@biomejs/biome": "2.0.6",
"@mdx-js/mdx": "3.1.1",
"@octokit/rest": "^22.0.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/workflow-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@
"test:watch": "vitest"
},
"dependencies": {
"@babel/parser": "8.1.2",
"@babel/parser": "7.29.9",
"@noble/hashes": "2.2.0",
"@sim/utils": "workspace:*",
"@sim/workflow-types": "workspace:*"
},
"devDependencies": {
"@babel/types": "8.1.2",
"@babel/types": "7.29.8",
"@sim/testing": "workspace:*",
"@sim/tsconfig": "workspace:*",
"@xyflow/react": "12.12.1",
Expand Down
9 changes: 2 additions & 7 deletions packages/workflow-code/src/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* The Babel AST walk and error reading shared by the compiler and the code-file reader.
*/

import type { MemberExpression, Node, OptionalMemberExpression } from '@babel/types'
import type { MemberExpression, Node } from '@babel/types'
import { isIndexSegment, isNameSegment, type RefSegment } from './code-files/ref-path'

/** The fields a thrown or recovered Babel error may carry. */
Expand Down Expand Up @@ -47,14 +47,9 @@ export function childNodes(node: Node): Node[] {
return children
}

/** Whether `node` is a member access, optional or not. */
export function isMemberAccess(node: Node): node is MemberExpression | OptionalMemberExpression {
return node.type === 'MemberExpression' || node.type === 'OptionalMemberExpression'
}

/** The name a member access reads: `.name` or `['name']` (optional or not); `null` otherwise. */
export function memberName(node: Node): string | null {
if (!isMemberAccess(node)) return null
if (node.type !== 'MemberExpression' && node.type !== 'OptionalMemberExpression') return null
if (!node.computed && node.property.type === 'Identifier') return node.property.name
return node.property.type === 'StringLiteral' ? node.property.value : null
}
Expand Down
9 changes: 3 additions & 6 deletions packages/workflow-code/src/code-files/from-file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ParserOptions, parse } from '@babel/parser'
import type { MemberExpression, Node } from '@babel/types'
import type { Expression, MemberExpression, Node } from '@babel/types'
import { isLikelyWorkflowReferenceSegment } from '@sim/utils/workflow-references'
import { babelErrorShape, childNodes, memberSegment } from '../babel'
import { ENV_VAR_NAME, formatStoredPath, type RefSegment } from './ref-path'
Expand Down Expand Up @@ -106,10 +106,7 @@ function isParenthesized(node: Node): boolean {
}

/** The members of a chain, innermost first, and its root; stops at a parenthesized object. */
function flattenChain(top: MemberExpression): {
root: MemberExpression['object']
members: MemberExpression[]
} {
function flattenChain(top: MemberExpression): { root: Expression; members: MemberExpression[] } {
const members: MemberExpression[] = [top]
let object = top.object
while (object.type === 'MemberExpression' && !isParenthesized(object)) {
Expand All @@ -136,7 +133,7 @@ function envName(member: MemberExpression): string | null {
* rooted at `$ref`/`$env` or maps no member.
*/
function chainReplacement(
root: MemberExpression['object'],
root: Expression,
members: MemberExpression[]
): { replacement: Replacement; consumed: number } | null {
if (root.type !== 'Identifier' || members.length === 0) return null
Expand Down
8 changes: 3 additions & 5 deletions packages/workflow-code/src/compile/function-returns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import { parse } from '@babel/parser'
import type { Expression, Node, ObjectExpression, PatternLike } from '@babel/types'
import { childNodes, isMemberAccess, memberName } from '../babel'
import { childNodes, memberName } from '../babel'
import { parseStoredPath } from '../code-files/ref-path'
import { toCodeFile } from '../code-files/to-file'
import type { BlockKey, CanonicalBlock } from '../model'
Expand Down Expand Up @@ -295,9 +295,8 @@ class Inference {
if (BOOLEAN_FUNCTIONS.has(callee.name)) return 'boolean'
return undefined
}
if (!isMemberAccess(callee)) return undefined
const method = memberName(callee)
if (method === null) return undefined
if (method === null || !('object' in callee)) return undefined
if (callee.object.type === 'Identifier') {
if (callee.object.name === 'Math') return this.isBuiltin('Math') ? 'number' : undefined
const known = STATIC_KINDS[`${callee.object.name}.${method}`]
Expand Down Expand Up @@ -357,9 +356,8 @@ class Inference {
private isArray(node: Node, strict = false): boolean {
if (node.type === 'ArrayExpression') return true
if (node.type === 'CallExpression' || node.type === 'OptionalCallExpression') {
if (!isMemberAccess(node.callee)) return false
const method = memberName(node.callee)
if (method === null) return false
if (method === null || !('object' in node.callee)) return false
if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'Object') {
return (
this.isBuiltin('Object') &&
Expand Down
1 change: 1 addition & 0 deletions packages/workflow-code/src/compile/hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export function hintForNode(node: Node): string {
case 'YieldExpression':
case 'ThisExpression':
case 'Super':
case 'Import':
case 'ImportExpression':
case 'MetaProperty':
return HINTS.calls
Expand Down
6 changes: 2 additions & 4 deletions packages/workflow-code/src/compile/values.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
ArrayExpression,
CallExpression,
Expression,
MemberExpression,
Node,
ObjectExpression,
Expand Down Expand Up @@ -532,10 +533,7 @@ function singleStringArgument(
return { text, node: argument }
}

function flattenMembers(node: MemberExpression): {
root: MemberExpression['object']
members: MemberExpression[]
} {
function flattenMembers(node: MemberExpression): { root: Expression; members: MemberExpression[] } {
const members: MemberExpression[] = [node]
let object = node.object
while (object.type === 'MemberExpression') {
Expand Down
4 changes: 2 additions & 2 deletions packages/workspace-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@
"test:watch": "vitest"
},
"dependencies": {
"@babel/parser": "8.1.2",
"@babel/parser": "7.29.9",
"@sim/table-cells": "workspace:*",
"@sim/utils": "workspace:*",
"@sim/workflow-code": "workspace:*"
},
"devDependencies": {
"@babel/types": "8.1.2",
"@babel/types": "7.29.8",
"@sim/testing": "workspace:*",
"@sim/tsconfig": "workspace:*",
"@types/js-yaml": "4.0.9",
Expand Down
11 changes: 7 additions & 4 deletions scripts/check-source-conventions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,14 @@ function isBarrel(file: string): boolean {
return /(?:^|\/)index\.tsx?$/.test(file)
}

/** The specifier of `import('x')` or `require('x')`. */
/** The specifier of `import('x')` or `require('x')`, in either AST shape Babel produces. */
function dynamicSpecifier(node: Node): string | undefined {
if (node.type === 'ImportExpression') return stringValue(node.source)
if (node.type !== 'CallExpression') return undefined
const callee = node.callee as Node
const isRequire = callee.type === 'Identifier' && callee.name === 'require'
return isRequire ? stringValue((node.arguments as Node[])[0]) : undefined
const isImportOrRequire =
callee.type === 'Import' || (callee.type === 'Identifier' && callee.name === 'require')
return isImportOrRequire ? stringValue((node.arguments as Node[])[0]) : undefined
}

/** The specifier of a static `import`, `import x = require()`, or `export … from`. */
Expand Down Expand Up @@ -272,7 +273,9 @@ function isBarrelReExport(node: Node, specifier: string, reExported: Set<string>

/** The specifier of a type-position `import('./x').T`. */
function importTypeSpecifier(node: Node): string | undefined {
return node.type === 'TSImportType' ? stringValue(node.source) : undefined
if (node.type !== 'TSImportType') return undefined
const argument = node.argument as Node
return stringValue(argument.type === 'TSLiteralType' ? argument.literal : argument)
}

function findRelativeImports(file: string, program: Node): Violation[] {
Expand Down
21 changes: 18 additions & 3 deletions scripts/check-sql-date-binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,27 @@ function collectSqlBindings(program: SyntaxNode): SqlBindings {
return bindings
}

/** `import('drizzle-orm')`, with or without an `await`. */
/**
* `import('drizzle-orm')`, with or without an `await`.
*
* Babel parses a dynamic import as a `CallExpression` whose callee is `Import`;
* the `ImportExpression` spelling is accepted too so a parser upgrade cannot
* silently reopen the hole this closes.
*/
function isDrizzleImportCall(node: unknown): boolean {
if (!isSyntaxNode(node)) return false
const current = node.type === 'AwaitExpression' ? unwrapAwait(node) : node
if (!isSyntaxNode(current) || current.type !== 'ImportExpression') return false
return isSyntaxNode(current.source) && isDrizzleModule(current.source.value)
if (!isSyntaxNode(current)) return false
const isImport =
current.type === 'ImportExpression' ||
(current.type === 'CallExpression' &&
isSyntaxNode(current.callee) &&
current.callee.type === 'Import')
if (!isImport) return false
const args = Array.isArray(current.arguments) ? current.arguments : []
const source = isSyntaxNode(current.source) ? current.source : args.find(isSyntaxNode)
const value = source?.value
return isDrizzleModule(value)
}

const unwrapAwait = (node: SyntaxNode): unknown =>
Expand Down
7 changes: 6 additions & 1 deletion scripts/check-test-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,12 @@ function centralMockName(

/** A dynamic `import('@sim/testing/…')`. */
function importsTesting(node: Node | undefined): boolean {
const source = node?.type === 'ImportExpression' ? (node.source as Node) : undefined
const source =
node?.type === 'CallExpression' && (node.callee as Node).type === 'Import'
? (node.arguments as Node[])[0]
: node?.type === 'ImportExpression'
? (node.source as Node)
: undefined
return (
source?.type === 'StringLiteral' &&
(source as { value: string }).value.startsWith('@sim/testing')
Expand Down
Loading