compile `script setup` components to components with `setup()` returning a render function

This issue has been created since 2022-10-23.

What problem does this feature solve?

Currently script setup components are compiled to a code where setup() function returns all data used in the template, components have also components property like you'd define it in normal script.

In Vue 3 setup() returns a render function that is accessing local variables and imported components directly which results in a smaller size of the bundle not only because of shorter code before minification but also because all variable and component names can be shortened to single letters. Would be great if Vue 2 behaved the same way, maybe some compiler configuration option could be used to force this?

What does the proposed API look like?

{
      __name: 'MyComponent',
      props: { prop1: Object, prop2: Boolean },
      setup (s) {
        const e = s, d = whatever();
        return () => h(a.B, ...)
      }
    }

instead of

{
      __name: 'MyComponent',
      components: { Foo: a.B, Bar: c.d },
      props: { prop1: Object, prop2: Boolean },
      setup (s) {
        const e = s, d = whatever();
        return { __sfc: !0, props: e, someData: d };
      }
    }
yyx990803 wrote this answer on 2022-11-09

This is currently a non-goal because Vue 2's template-to-render-fn compilation was written in a way that does not perform any JS expression parsing (it is done in a separate pass with other tools). So the whole process does not have the necessary information to prefix/unwrap refs based on <script setup> scope information. This is only possible if we completely rework Vue 2's template compilation, but that would be a big and risky refactor which we for now don't plan to do.

More Details About Repo
Owner Name vuejs
Repo Name vue
Full Name vuejs/vue
Language TypeScript
Created Date 2013-07-29
Updated Date 2022-12-10
Star Count 201155
Watcher Count 6070
Fork Count 33134
Issue Count 595

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
No support for passphrase-protected SP privateKey 3 2015-05-28 2022-12-02
subpatches sometimes load empty 3 2022-08-26 2022-11-26
site showing less servers than added 2 2022-08-18 2022-12-05
Stable 0.15.0 Release? 2 2021-06-02 2022-05-05
Change of parameters from defaults are possibly ignored 0 2021-11-15 2022-09-06
MockFileStream.InternalFlush is not thread-safe 2 2021-12-28 2022-10-17
Inaccurate Description of Microsoft/Oracle in Enterprise Python 0 2021-03-22 2022-10-10
Declare missing dependencies 1 2020-05-22 2022-12-03
Support for MCP23016 2 2020-06-28 2022-09-19
The performance seem dropped twice since last year 16 2022-11-25 2022-12-03
Firefox-qsplugin bookmarks not working 3 2022-02-24 2022-07-26
Crash: thiS is not defined 1 2022-07-20 2022-11-12
奖励文字能否设置多行,并且单独设置大小与颜色 1 2022-03-04 2022-11-30
Problem install_jetson.sh 0 2021-10-10 2022-11-14
[CMI] Color module needs to regenerate CSS files during config import 4 2015-03-02 2022-09-29
Can't generate a file in the background to attach it to activestorage 1 2021-02-04 2022-11-12
After using docker to pull the image for installation, the document server can be accessed successfully, but a serious error will be prompted when editing the file, which makes it impossible to edit 5 2022-08-19 2022-11-15
`:w` to save new file failed 10 2021-06-02 2022-10-18
The Patcher setting reverts to default after reboot [Bug]: 2 2021-08-19 2022-09-21
Backport Security Fix to 6.2.1 15 2021-06-01 2022-12-03
SDL_SetWindowMouseGrab() in fullscreen windows 0 2022-09-18 2022-10-24
🔥 connect/connect-weblogic-source 2 2021-12-16 2022-01-19
Filtering problem on data table 10 2020-05-07 2022-11-18
ToString test fails when run in a French locale 5 2022-09-21 2022-10-15
Adjust table column names for proper formatting and standardized naming conventions 1 2021-09-23 2022-10-09
Search (xml) fails to include full URI 0 2021-05-30 2022-11-28
Handheld search icon refreshes page 2 2021-09-27 2022-11-26
Discussion: Comparison to my rethought proposal 15 2018-03-13 2022-12-09
Book a Corona test in the app - Both rapid and PCR-based 15 2021-03-17 2022-11-12
panic: runtime error: index out of range [-1] 18 2021-09-07 2022-12-10
segment fault4 3 2021-03-17 2021-12-07
www.yenialanya.com 0 2021-12-27 2021-12-21
[TTFNet and PAFNet implemention !!!] TTFNet and it’s improved version called PAFNet has been implemented in PaddleDetection, welcome to use it for research or engineering! 1 2021-09-19 2022-11-25
TileSet "tile_get_region" does not work for ATLAS_TILE or AUTO_TILE Tile Modes 1 2022-11-10 2022-11-12
allow plugins to define subplugins 2 2021-04-12 2022-09-18
Measure firmware configuration file data in DXE phase 0 2021-03-23 2022-11-12
Fail to read video files 3 2015-09-13 2022-10-06
libc version causes MacOS compilation failure 2 2021-01-05 2022-11-17
spray alarm & night time detection levels & cam disconnect alert 11 2021-09-17 2022-11-16
az & azure-cli-ml extension for deploying model 5 2022-09-03 2022-11-25
Don't create premium namespace when running New-TestResources locally 1 2021-10-01 2022-11-06
test linux-docs / build-docs (python) is broken 3 2022-03-24 2022-12-03
Support workload cluster upgrade plan 0 2022-05-11 2022-09-18
Example code crashes on linux 0 2021-06-04 2022-12-06
IIFE w/ throw error in default value of destructuring assignment produces false positive 'unreachable code detected.' 1 2022-07-02 2022-10-10
插件更新,AndroidX 2 2020-11-04 2022-01-11
Connection timeouts can cause incorrect message code error [JIRA: CLIENTS-766] 0 2016-02-12 2022-11-25
[Flake] TestPriorityAndFairnessWithPanicRecoveryAndTimeoutFilter flaking 14 2022-07-14 2022-11-04
[Password Hashing] Interface implementation 0 2022-07-27 2022-11-18
ValidateNever applied to action parameters is not honored 5 2022-09-30 2022-10-04