diff --git a/package.json b/package.json index b17f4f6eb..a67291eb4 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@pnpm/logger": "^4.0.0", "@sxzz/eslint-config": "^2.4.1", "@types/node": "*", + "@vitest/ui": "^0.22.1", "@vue-macros/test-utils": "workspace:*", "bumpp": "^8.2.1", "eslint": "^8.23.0", diff --git a/packages/define-model/package.json b/packages/define-model/package.json index 93b4d92de..6bce211b6 100644 --- a/packages/define-model/package.json +++ b/packages/define-model/package.json @@ -70,7 +70,7 @@ "dependencies": { "@rollup/pluginutils": "^4.2.1", "@vue-macros/common": "workspace:*", - "ast-walker-scope": "^0.2.2", + "ast-walker-scope": "^0.2.3", "unplugin": "^0.9.5" }, "devDependencies": { diff --git a/packages/define-options/package.json b/packages/define-options/package.json index 8c822d28a..2185d628b 100644 --- a/packages/define-options/package.json +++ b/packages/define-options/package.json @@ -69,7 +69,7 @@ "dependencies": { "@rollup/pluginutils": "^4.2.1", "@vue-macros/common": "workspace:*", - "ast-walker-scope": "^0.2.2", + "ast-walker-scope": "^0.2.3", "unplugin": "^0.9.5" }, "devDependencies": { diff --git a/packages/define-options/src/core/transform.ts b/packages/define-options/src/core/transform.ts index b035ab0be..33151392c 100644 --- a/packages/define-options/src/core/transform.ts +++ b/packages/define-options/src/core/transform.ts @@ -27,8 +27,8 @@ export const transform = (code: string, id: string) => { if (script) checkDefaultExport(scriptCompiled.scriptAst as any) - const scriptBindings = sfc.scriptCompiled.scriptSetupAst - ? getIdentifiers(sfc.scriptCompiled.scriptSetupAst as any) + const setupBindings = scriptCompiled.scriptSetupAst + ? getIdentifiers(scriptCompiled.scriptSetupAst as any) : [] const s = new MagicString(code) @@ -51,7 +51,7 @@ export default /*#__PURE__*/ DO_defineComponent(` `${DEFINE_OPTIONS}() please use defineProps or defineEmits instead.` ) - checkInvalidScopeReference(arg, DEFINE_OPTIONS, scriptBindings) + checkInvalidScopeReference(arg, DEFINE_OPTIONS, setupBindings) s.moveNode(arg, scriptOffset, { offset: setupOffset }) diff --git a/packages/macros/tests/__snapshots__/fixtures.test.ts.snap b/packages/macros/tests/__snapshots__/fixtures.test.ts.snap index b20e5e742..31b0cfccb 100644 --- a/packages/macros/tests/__snapshots__/fixtures.test.ts.snap +++ b/packages/macros/tests/__snapshots__/fixtures.test.ts.snap @@ -80,6 +80,37 @@ export { hoistStatic as default }; " `; +exports[`fixtures > tests/fixtures/hoist-static-scope.vue 1`] = ` +"import { defineComponent, openBlock, createElementBlock } from 'vue'; + +const [name] = [\\"VarCompName\\"]; +const __default__ = defineComponent({ + name +}); +var _sfc_main = /* @__PURE__ */ defineComponent({ + ...__default__, + setup(__props) { + const test = (name2) => name2; + return (_ctx, _cache) => { + return openBlock(), createElementBlock(\\"div\\", null, \\"1\\"); + }; + } +}); + +var _export_sfc = (sfc, props) => { + const target = sfc.__vccOpts || sfc; + for (const [key, val] of props) { + target[key] = val; + } + return target; +}; + +var hoistStaticScope = /* @__PURE__ */ _export_sfc(_sfc_main, [__FILE__]); + +export { hoistStaticScope as default }; +" +`; + exports[`fixtures > tests/fixtures/vue2-model.vue 1`] = ` "import { defineComponent } from 'vue'; diff --git a/packages/macros/tests/fixtures/hoist-static-scope.vue b/packages/macros/tests/fixtures/hoist-static-scope.vue new file mode 100644 index 000000000..f851fc283 --- /dev/null +++ b/packages/macros/tests/fixtures/hoist-static-scope.vue @@ -0,0 +1,14 @@ + + + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e1451020..cfa35952d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,7 @@ importers: '@pnpm/logger': ^4.0.0 '@sxzz/eslint-config': ^2.4.1 '@types/node': '*' + '@vitest/ui': ^0.22.1 '@vue-macros/test-utils': workspace:* bumpp: ^8.2.1 eslint: ^8.23.0 @@ -25,6 +26,7 @@ importers: '@pnpm/logger': 4.0.0 '@sxzz/eslint-config': 2.4.1_nglnstp6khxsch65otolmbe4hy '@types/node': 18.7.13 + '@vitest/ui': 0.22.1 '@vue-macros/test-utils': link:packages/test-utils bumpp: 8.2.1 eslint: 8.23.0 @@ -35,7 +37,7 @@ importers: tsx: 3.8.2 typescript: 4.8.2 vite: 3.0.9 - vitest: 0.22.1 + vitest: 0.22.1_@vitest+ui@0.22.1 vue: 3.2.37 packages/common: @@ -60,7 +62,7 @@ importers: '@babel/types': ^7.18.13 '@rollup/pluginutils': ^4.2.1 '@vue-macros/common': workspace:* - ast-walker-scope: ^0.2.2 + ast-walker-scope: ^0.2.3 fast-glob: ^3.2.11 tsup: ^6.2.3 tsx: ^3.8.2 @@ -70,7 +72,7 @@ importers: dependencies: '@rollup/pluginutils': 4.2.1 '@vue-macros/common': link:../common - ast-walker-scope: 0.2.2 + ast-walker-scope: 0.2.3 unplugin: 0.9.5_vite@3.0.9 devDependencies: '@babel/types': 7.18.13 @@ -85,7 +87,7 @@ importers: '@babel/types': ^7.18.13 '@rollup/pluginutils': ^4.2.1 '@vue-macros/common': workspace:* - ast-walker-scope: ^0.2.2 + ast-walker-scope: ^0.2.3 fast-glob: ^3.2.11 rollup: ^2.78.1 tsup: ^6.2.3 @@ -96,7 +98,7 @@ importers: dependencies: '@rollup/pluginutils': 4.2.1 '@vue-macros/common': link:../common - ast-walker-scope: 0.2.2 + ast-walker-scope: 0.2.3 unplugin: 0.9.5_rollup@2.78.1+vite@3.0.9 devDependencies: '@babel/types': 7.18.13 @@ -2050,6 +2052,12 @@ packages: vue: 3.2.37 dev: true + /@vitest/ui/0.22.1: + resolution: {integrity: sha512-iiM2JN+vzY8pEejUbPPi0EgkEselI3RvrgMPNUOalxQRgtlNVGyMsM0Re99xQsrZ/eBkHgWrlW216gNDoeD5cA==} + dependencies: + sirv: 2.0.2 + dev: true + /@volar/code-gen/0.40.2: resolution: {integrity: sha512-1Z08SJkJOdQiXYdDpwOynLz/grL50uENz65qmQLpgaN12WiekkdWqeFOZSlB9FbWgB686wBnlAV8sxUqWtoSmA==} dependencies: @@ -2555,8 +2563,8 @@ packages: resolution: {integrity: sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==} dev: true - /ast-walker-scope/0.2.2: - resolution: {integrity: sha512-+EQ7NoxFlwQEwrOIE4gMX7inkDs8sRQyibpRO4e3DxY2r9bANrEfZbL3NrkvqwZItKTANDYUKyW04eZXtabetw==} + /ast-walker-scope/0.2.3: + resolution: {integrity: sha512-9reB+iYF6jCCDqKDNNQI8iA2MJcy0jCLvEjfya72F7Zai5i2CB8hk9K/kzkZhagja9othQCFPEvQW11LhPKjmg==} engines: {node: '>=14.19.0'} dependencies: '@babel/parser': 7.18.13 @@ -7082,7 +7090,7 @@ packages: optionalDependencies: fsevents: 2.3.2 - /vitest/0.22.1: + /vitest/0.22.1_@vitest+ui@0.22.1: resolution: {integrity: sha512-+x28YTnSLth4KbXg7MCzoDAzPJlJex7YgiZbUh6YLp0/4PqVZ7q7/zyfdL0OaPtKTpNiQFPpMC8Y2MSzk8F7dw==} engines: {node: '>=v14.16.0'} hasBin: true @@ -7107,6 +7115,7 @@ packages: '@types/chai': 4.3.3 '@types/chai-subset': 1.3.3 '@types/node': 18.7.13 + '@vitest/ui': 0.22.1 chai: 4.3.6 debug: 4.3.4 local-pkg: 0.4.2