Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(plugincontract): handle async methods and top-level for-await in surface validation (#11101)
T Mohan Aditya66679d864215
diff --git a/server/pkg/plugincontract/bundle.go b/server/pkg/plugincontract/bundle.goindex d6fd4bbb53..44803bb06e 100644--- a/server/pkg/plugincontract/bundle.go+++ b/server/pkg/plugincontract/bundle.go@@ -292,6 +292,21 @@ func (v *surfaceModuleSyntaxVisitor) Enter(node js.INode) js.IVisitor {if node.Op == js.AwaitToken && v.functionDepth == 0 {v.moduleOnly = true}+ case *js.ForOfStmt:+ if node.Await && v.functionDepth == 0 {+ v.moduleOnly = true+ }+ case *js.MethodDecl:+ js.Walk(v, &node.Name.PropertyName)+ v.functionDepth+++ js.Walk(v, &node.Params)+ js.Walk(v, &node.Body)+ v.functionDepth--+ return nil+ case *js.Field:+ js.Walk(v, &node.Name.PropertyName)+ js.Walk(v, node.Init)+ return nilcase *js.FuncDecl, *js.ArrowFunc:v.functionDepth++}diff --git a/server/pkg/plugincontract/bundle_test.go b/server/pkg/plugincontract/bundle_test.goindex bd44b69af1..b46a709322 100644--- a/server/pkg/plugincontract/bundle_test.go+++ b/server/pkg/plugincontract/bundle_test.go@@ -235,17 +235,23 @@ func TestParseBundleFromDirMatchesTheUploadPath(t *testing.T) {// blocks a legitimate publish outright. This pins both directions.func TestSurfaceEntryModuleDetection(t *testing.T) {refused := map[string]string{- "bare import": "import { multica } from \"./sdk.js\";\n",- "indented import": " import { multica } from \"./sdk.js\";\n",- "import after a line comment": "// set up\nimport { multica } from \"./sdk.js\";\n",- "import after a block comment": "/* set up */ import { multica } from \"./sdk.js\";\n",- "namespace import": "import * as sdk from \"./sdk.js\";\n",- "named export": "export { render };\n",- "import after another statement": "const x = 1; import y from \"./y.js\";\n",- "export after another statement": "const x = 1; export { x };\n",- "import inside a function": "function boot() {\n import { x } from \"./x.js\";\n}\n",- "top-level await": "await 1;\n",- "import meta": "console.log(import.meta.url);\n",+ "bare import": "import { multica } from \"./sdk.js\";\n",+ "indented import": " import { multica } from \"./sdk.js\";\n",+ "import after a line comment": "// set up\nimport { multica } from \"./sdk.js\";\n",+ "import after a block comment": "/* set up */ import { multica } from \"./sdk.js\";\n",+ "namespace import": "import * as sdk from \"./sdk.js\";\n",+ "named export": "export { render };\n",+ "import after another statement": "const x = 1; import y from \"./y.js\";\n",+ "export after another statement": "const x = 1; export { x };\n",+ "import inside a function": "function boot() {\n import { x } from \"./x.js\";\n}\n",+ "top-level await": "await 1;\n",+ "top-level for await": "for await (const item of items) { console.log(item); }\n",+ "top-level await in computed class method key": "class Panel { async [await key()]() {} }\n",+ "top-level await in computed object method key": "const api = { async [await key()]() {} };\n",+ "import meta": "console.log(import.meta.url);\n",+ "import meta in computed class method key": "class Panel { [import.meta.url]() {} }\n",+ "import meta in computed class field key": "class Panel { [import.meta.url] = 1; }\n",+ "import meta inside async class method": "class Panel { async boot() { return import.meta.url; } }\n",}for name, source := range refused {t.Run(name, func(t *testing.T) {@@ -262,15 +268,20 @@ func TestSurfaceEntryModuleDetection(t *testing.T) {"import inside a string": "const help = \"import x from 'y'\";\nconsole.log(help);\n","import inside a comment": "// import { x } from \"./x.js\";\nconsole.log(1);\n",// Dynamic import is legal in a classic script.- "dynamic import": "const load = () => import(\"./late.js\");\nload();\n",- "spaced dynamic import": "const load = () => import (\"./late.js\");\nload();\n",- "commented dynamic import": "const load = () => import /* webpackIgnore */ (\"https://example.com/late.js\");\nload();\n",- "regexp containing import": "const matcher = /import y from ['\"]x['\"]/;\nconsole.log(matcher);\n",- "a property named import": "const registry = {};\nregistry.import = 1;\n",- "a word starting with export": "const exports = {};\nexports.value = 1;\n",- "nested template expression": "const x = `a${ `b` }c`;\nconsole.log(x);\n",- "await in an async function": "async function boot() { await Promise.resolve(); }\nboot();\n",- "await in an async arrow": "const boot = async () => { await Promise.resolve(); };\nboot();\n",+ "dynamic import": "const load = () => import(\"./late.js\");\nload();\n",+ "spaced dynamic import": "const load = () => import (\"./late.js\");\nload();\n",+ "commented dynamic import": "const load = () => import /* webpackIgnore */ (\"https://example.com/late.js\");\nload();\n",+ "regexp containing import": "const matcher = /import y from ['\"]x['\"]/;\nconsole.log(matcher);\n",+ "a property named import": "const registry = {};\nregistry.import = 1;\n",+ "a word starting with export": "const exports = {};\nexports.value = 1;\n",+ "nested template expression": "const x = `a${ `b` }c`;\nconsole.log(x);\n",+ "await in an async function": "async function boot() { await Promise.resolve(); }\nboot();\n",+ "await in an async arrow": "const boot = async () => { await Promise.resolve(); };\nboot();\n",+ "await in an async class method": "class Panel { async boot() { await Promise.resolve(); } }\nnew Panel().boot();\n",+ "await in an async object method": "const api = { async load() { await Promise.resolve(); } };\napi.load();\n",+ "for await in an async function": "async function read(s) { for await (const x of s) { console.log(x); } }\nread([]);\n",+ "for await in an async generator method": "class Stream { async *items(s) { for await (const x of s) { yield x; } } }\nnew Stream();\n",+ "await in computed method key inside async": "async function make() { return { async [await Promise.resolve('k')]() { await Promise.resolve(); } }; }\nmake();\n",}for name, source := range accepted {t.Run(name, func(t *testing.T) {