diff --git a/bun.lock b/bun.lock index d635b56d614..9bf4a934c7f 100644 --- a/bun.lock +++ b/bun.lock @@ -5,7 +5,7 @@ "": { "name": "simstudio", "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", @@ -871,13 +871,13 @@ "name": "@sim/workflow-code", "version": "0.1.0", "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", @@ -971,13 +971,13 @@ "name": "@sim/workspace-code", "version": "0.1.0", "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", @@ -1270,7 +1270,7 @@ "@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@7.29.7", "", {}, "sha512-qehxGkRj55h/ff8EMaJ+cYhyaKlHIxqYDn682wQD7RNp9UujOQsHog2uS0r2vzr4pW+sXf90NeeayjcNaX3fFg=="], - "@babel/parser": ["@babel/parser@8.1.2", "", { "dependencies": { "@babel/types": "^8.1.2" }, "bin": "./bin/babel-parser.js" }, "sha512-ZDKU7vaX0VORd2BhaO+3FKr/30TKjbUy3SMZcydiPngnAb+MesgUoh5SJcE5EwEyBj14M5J6fK56GuBqvYmOpw=="], + "@babel/parser": ["@babel/parser@7.29.9", "", { "dependencies": { "@babel/types": "^7.29.8" }, "bin": "./bin/babel-parser.js" }, "sha512-CjXrNHTnvqBVqHgdBysY3vk2T8tpJHb5/RMeHJBTyVa9xgugCB0CJTx/3oO8RV2QRQP391RWpB7D6hLjm8V9uA=="], "@babel/runtime": ["@babel/runtime@7.29.7", "", {}, "sha512-Nq8OhGWiZIZGV6hLHoyAKLLcJihP/xFeBMGJoUrxTX2psI8dCifzLhZISFb+VWS3wFMRDmCGw5R+dOySCqPLhw=="], @@ -4962,8 +4962,6 @@ "@babel/generator/@babel/types": ["@babel/types@7.29.7", "", { "dependencies": { "@babel/helper-string-parser": "^7.29.7", "@babel/helper-validator-identifier": "^7.29.7" } }, "sha512-4zBIxpPzowiZpusoFkyGVwakdRJUyuH5PxQ/PrqghfdFWWasvnCdPfQXHrenDai+gyLARulZjZowCOj6fjT4pA=="], - "@babel/parser/@babel/types": ["@babel/types@8.1.2", "", { "dependencies": { "@babel/helper-string-parser": "^8.1.2", "@babel/helper-validator-identifier": "^8.0.6" } }, "sha512-uXt6qt2f5G61jZwNIzK1RKu7l5Xjt1VXtPPOGuVveha9fxbx0QM94U1kM4pFZKTRLjWK+X8vmwjwbIemJjiQTA=="], - "@babel/template/@babel/parser": ["@babel/parser@7.29.7", "", { "dependencies": { "@babel/types": "^7.29.7" }, "bin": "./bin/babel-parser.js" }, "sha512-hnORnjP/1P/zFEndoeX+n+t1RwWRJiJpM/jO7FW32Kn9r5+sJB2JWOdYo4L6k78j15eCwY3Gm/7364B1EMwtNg=="], "@babel/template/@babel/types": ["@babel/types@7.29.7", "", { "dependencies": { "@babel/helper-string-parser": "^7.29.7", "@babel/helper-validator-identifier": "^7.29.7" } }, "sha512-4zBIxpPzowiZpusoFkyGVwakdRJUyuH5PxQ/PrqghfdFWWasvnCdPfQXHrenDai+gyLARulZjZowCOj6fjT4pA=="], @@ -5080,12 +5078,6 @@ "@shuding/opentype.js/fflate": ["fflate@0.7.5", "", {}, "sha512-QieYf//cis6ywHNi5qW1+PXPQ4bC+XVJAtS4AXIML8P76GroEiOxm/oQtn1f02UkJY1+KsXMJcC+R2v/Eg4G3g=="], - "@sim/app/@babel/parser": ["@babel/parser@7.29.9", "", { "dependencies": { "@babel/types": "^7.29.8" }, "bin": "./bin/babel-parser.js" }, "sha512-CjXrNHTnvqBVqHgdBysY3vk2T8tpJHb5/RMeHJBTyVa9xgugCB0CJTx/3oO8RV2QRQP391RWpB7D6hLjm8V9uA=="], - - "@sim/workflow-code/@babel/types": ["@babel/types@8.1.2", "", { "dependencies": { "@babel/helper-string-parser": "^8.1.2", "@babel/helper-validator-identifier": "^8.0.6" } }, "sha512-uXt6qt2f5G61jZwNIzK1RKu7l5Xjt1VXtPPOGuVveha9fxbx0QM94U1kM4pFZKTRLjWK+X8vmwjwbIemJjiQTA=="], - - "@sim/workspace-code/@babel/types": ["@babel/types@8.1.2", "", { "dependencies": { "@babel/helper-string-parser": "^8.1.2", "@babel/helper-validator-identifier": "^8.0.6" } }, "sha512-uXt6qt2f5G61jZwNIzK1RKu7l5Xjt1VXtPPOGuVveha9fxbx0QM94U1kM4pFZKTRLjWK+X8vmwjwbIemJjiQTA=="], - "@smithy/core/tslib": ["tslib@2.8.1", "", {}, "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w=="], "@smithy/credential-provider-imds/@smithy/core": ["@smithy/core@3.33.3", "", { "dependencies": { "@smithy/types": "^4.17.2", "tslib": "^2.6.2" } }, "sha512-CsOeKq/9kA3y6VJHt+/+VTCtBaxJ4OTFpgrjIUhPpDIKxBci1k2bJaQASF2h/ELWrulGp+t97DZ0mevfAD8idg=="], @@ -5550,10 +5542,6 @@ "@aws-crypto/util/@aws-sdk/types/@smithy/types": ["@smithy/types@4.15.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-Z5TAOxygoFvybJV3igo5SloFflSokHx2hu1eFA+DxDTcn+FtKxUSui+rbTRG1pAafMA888Z3MVvCWUuvCrTXjg=="], - "@babel/parser/@babel/types/@babel/helper-string-parser": ["@babel/helper-string-parser@8.1.2", "", {}, "sha512-TRz5Z0MgfIfWqwEIq/pCpUpEXQxUt2Ig2ZbxG3SdmhSbHMAFFYGOix0kI4JLV371/TA+qWnQ4xWHPWjojkyRFA=="], - - "@babel/parser/@babel/types/@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@8.0.6", "", {}, "sha512-HYx0YmuchRxRSpnjvcNffnPS8DCauKNmnumIuHG3jnQAVewRA7kfJGwF13ayEpSZs7s4R/oBH4eppuXcAQd5JQ=="], - "@better-auth/sso/tldts/tldts-core": ["tldts-core@6.1.86", "", {}, "sha512-Je6p7pkk+KMzMv2XXKmAE3McmolOQFdxkKw0R8EYNr7sELW46JqnNeTX8ybPiQgvg1ymCoF8LXs5fzFaZvJPTA=="], "@browserbasehq/sdk/@types/node/undici-types": ["undici-types@5.26.5", "", {}, "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA=="], @@ -5664,14 +5652,6 @@ "@react-email/render/html-to-text/selderee": ["selderee@0.12.0", "", { "dependencies": { "parseley": "~0.13.1" } }, "sha512-b1YMh3+DHZp59DLna3qVwQ5iOla/nrI6mLBNW02XxU77M3046Df6VLkoaJyFz20VsGIG5kkp+FK0kg4K4HnUFw=="], - "@sim/workflow-code/@babel/types/@babel/helper-string-parser": ["@babel/helper-string-parser@8.1.2", "", {}, "sha512-TRz5Z0MgfIfWqwEIq/pCpUpEXQxUt2Ig2ZbxG3SdmhSbHMAFFYGOix0kI4JLV371/TA+qWnQ4xWHPWjojkyRFA=="], - - "@sim/workflow-code/@babel/types/@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@8.0.6", "", {}, "sha512-HYx0YmuchRxRSpnjvcNffnPS8DCauKNmnumIuHG3jnQAVewRA7kfJGwF13ayEpSZs7s4R/oBH4eppuXcAQd5JQ=="], - - "@sim/workspace-code/@babel/types/@babel/helper-string-parser": ["@babel/helper-string-parser@8.1.2", "", {}, "sha512-TRz5Z0MgfIfWqwEIq/pCpUpEXQxUt2Ig2ZbxG3SdmhSbHMAFFYGOix0kI4JLV371/TA+qWnQ4xWHPWjojkyRFA=="], - - "@sim/workspace-code/@babel/types/@babel/helper-validator-identifier": ["@babel/helper-validator-identifier@8.0.6", "", {}, "sha512-HYx0YmuchRxRSpnjvcNffnPS8DCauKNmnumIuHG3jnQAVewRA7kfJGwF13ayEpSZs7s4R/oBH4eppuXcAQd5JQ=="], - "@smithy/eventstream-codec/@smithy/core/@smithy/types": ["@smithy/types@4.15.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-Z5TAOxygoFvybJV3igo5SloFflSokHx2hu1eFA+DxDTcn+FtKxUSui+rbTRG1pAafMA888Z3MVvCWUuvCrTXjg=="], "@smithy/util-utf8/@smithy/core/@smithy/types": ["@smithy/types@4.15.0", "", { "dependencies": { "tslib": "^2.6.2" } }, "sha512-Z5TAOxygoFvybJV3igo5SloFflSokHx2hu1eFA+DxDTcn+FtKxUSui+rbTRG1pAafMA888Z3MVvCWUuvCrTXjg=="], diff --git a/package.json b/package.json index 5341b7d309c..cbe0ee77763 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/workflow-code/package.json b/packages/workflow-code/package.json index 4310cea77e3..234173a8267 100644 --- a/packages/workflow-code/package.json +++ b/packages/workflow-code/package.json @@ -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", diff --git a/packages/workflow-code/src/babel.ts b/packages/workflow-code/src/babel.ts index 629de6d8718..bb3f94cdf1b 100644 --- a/packages/workflow-code/src/babel.ts +++ b/packages/workflow-code/src/babel.ts @@ -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. */ @@ -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 } diff --git a/packages/workflow-code/src/code-files/from-file.ts b/packages/workflow-code/src/code-files/from-file.ts index 3170891ddb0..9d81cbe57f1 100644 --- a/packages/workflow-code/src/code-files/from-file.ts +++ b/packages/workflow-code/src/code-files/from-file.ts @@ -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' @@ -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)) { @@ -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 diff --git a/packages/workflow-code/src/compile/function-returns.ts b/packages/workflow-code/src/compile/function-returns.ts index cd6f17f6a70..37c98d83d38 100644 --- a/packages/workflow-code/src/compile/function-returns.ts +++ b/packages/workflow-code/src/compile/function-returns.ts @@ -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' @@ -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}`] @@ -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') && diff --git a/packages/workflow-code/src/compile/hints.ts b/packages/workflow-code/src/compile/hints.ts index 7c06a2eea6e..5f0abc6bcb4 100644 --- a/packages/workflow-code/src/compile/hints.ts +++ b/packages/workflow-code/src/compile/hints.ts @@ -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 diff --git a/packages/workflow-code/src/compile/values.ts b/packages/workflow-code/src/compile/values.ts index 59e02f08aef..32486939295 100644 --- a/packages/workflow-code/src/compile/values.ts +++ b/packages/workflow-code/src/compile/values.ts @@ -1,6 +1,7 @@ import type { ArrayExpression, CallExpression, + Expression, MemberExpression, Node, ObjectExpression, @@ -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') { diff --git a/packages/workspace-code/package.json b/packages/workspace-code/package.json index 085c18a3653..36c432cfd6e 100644 --- a/packages/workspace-code/package.json +++ b/packages/workspace-code/package.json @@ -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", diff --git a/scripts/check-source-conventions.ts b/scripts/check-source-conventions.ts index 30e752cc744..ba4ce7ce89d 100644 --- a/scripts/check-source-conventions.ts +++ b/scripts/check-source-conventions.ts @@ -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`. */ @@ -272,7 +273,9 @@ function isBarrelReExport(node: Node, specifier: string, reExported: Set /** 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[] { diff --git a/scripts/check-sql-date-binding.ts b/scripts/check-sql-date-binding.ts index c1fab8e89e2..3078a7b89db 100644 --- a/scripts/check-sql-date-binding.ts +++ b/scripts/check-sql-date-binding.ts @@ -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 => diff --git a/scripts/check-test-patterns.ts b/scripts/check-test-patterns.ts index 21485a71e45..622bfba77ab 100644 --- a/scripts/check-test-patterns.ts +++ b/scripts/check-test-patterns.ts @@ -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')