compileScript.spec.ts 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554
  1. import { BindingTypes } from '@vue/compiler-core'
  2. import { compileSFCScript as compile, assertCode, mockId } from './utils'
  3. describe('SFC compile <script setup>', () => {
  4. test('should compile JS syntax', () => {
  5. const { content } = compile(`
  6. <script setup lang='js'>
  7. const a = 1
  8. const b = 2
  9. </script>
  10. `)
  11. expect(content).toMatch(`return { a, b }`)
  12. assertCode(content)
  13. })
  14. test('should expose top level declarations', () => {
  15. const { content, bindings } = compile(`
  16. <script setup>
  17. import { x } from './x'
  18. let a = 1
  19. const b = 2
  20. function c() {}
  21. class d {}
  22. </script>
  23. <script>
  24. import { xx } from './x'
  25. let aa = 1
  26. const bb = 2
  27. function cc() {}
  28. class dd {}
  29. </script>
  30. `)
  31. expect(content).toMatch(
  32. `return { get aa() { return aa }, set aa(v) { aa = v }, ` +
  33. `bb, cc, dd, get a() { return a }, set a(v) { a = v }, b, c, d, ` +
  34. `get xx() { return xx }, get x() { return x } }`
  35. )
  36. expect(bindings).toStrictEqual({
  37. x: BindingTypes.SETUP_MAYBE_REF,
  38. a: BindingTypes.SETUP_LET,
  39. b: BindingTypes.SETUP_CONST,
  40. c: BindingTypes.SETUP_CONST,
  41. d: BindingTypes.SETUP_CONST,
  42. xx: BindingTypes.SETUP_MAYBE_REF,
  43. aa: BindingTypes.SETUP_LET,
  44. bb: BindingTypes.LITERAL_CONST,
  45. cc: BindingTypes.SETUP_CONST,
  46. dd: BindingTypes.SETUP_CONST
  47. })
  48. assertCode(content)
  49. })
  50. test('binding analysis for destructure', () => {
  51. const { content, bindings } = compile(`
  52. <script setup>
  53. const { foo, b: bar, ['x' + 'y']: baz, x: { y, zz: { z }}} = {}
  54. </script>
  55. `)
  56. expect(content).toMatch('return { foo, bar, baz, y, z }')
  57. expect(bindings).toStrictEqual({
  58. foo: BindingTypes.SETUP_MAYBE_REF,
  59. bar: BindingTypes.SETUP_MAYBE_REF,
  60. baz: BindingTypes.SETUP_MAYBE_REF,
  61. y: BindingTypes.SETUP_MAYBE_REF,
  62. z: BindingTypes.SETUP_MAYBE_REF
  63. })
  64. assertCode(content)
  65. })
  66. describe('<script> and <script setup> co-usage', () => {
  67. test('script first', () => {
  68. const { content } = compile(`
  69. <script>
  70. export const n = 1
  71. export default {}
  72. </script>
  73. <script setup>
  74. import { x } from './x'
  75. x()
  76. </script>
  77. `)
  78. assertCode(content)
  79. })
  80. test('script setup first', () => {
  81. const { content } = compile(`
  82. <script setup>
  83. import { x } from './x'
  84. x()
  85. </script>
  86. <script>
  87. export const n = 1
  88. export default {}
  89. </script>
  90. `)
  91. assertCode(content)
  92. })
  93. // #7805
  94. test('keep original semi style', () => {
  95. const { content } = compile(`
  96. <script setup>
  97. console.log('test')
  98. const props = defineProps(['item']);
  99. const emit = defineEmits(['change']);
  100. (function () {})()
  101. </script>
  102. `)
  103. assertCode(content)
  104. expect(content).toMatch(`console.log('test')`)
  105. expect(content).toMatch(`const props = __props;`)
  106. expect(content).toMatch(`const emit = __emit;`)
  107. expect(content).toMatch(`(function () {})()`)
  108. })
  109. test('script setup first, named default export', () => {
  110. const { content } = compile(`
  111. <script setup>
  112. import { x } from './x'
  113. x()
  114. </script>
  115. <script>
  116. export const n = 1
  117. const def = {}
  118. export { def as default }
  119. </script>
  120. `)
  121. assertCode(content)
  122. })
  123. // #4395
  124. test('script setup first, lang="ts", script block content export default', () => {
  125. const { content } = compile(`
  126. <script setup lang="ts">
  127. import { x } from './x'
  128. x()
  129. </script>
  130. <script lang="ts">
  131. export default {
  132. name: "test"
  133. }
  134. </script>
  135. `)
  136. // ensure __default__ is declared before used
  137. expect(content).toMatch(/const __default__[\S\s]*\.\.\.__default__/m)
  138. assertCode(content)
  139. })
  140. describe('spaces in ExportDefaultDeclaration node', () => {
  141. // #4371
  142. test('with many spaces and newline', () => {
  143. // #4371
  144. const { content } = compile(`
  145. <script>
  146. export const n = 1
  147. export default
  148. {
  149. some:'option'
  150. }
  151. </script>
  152. <script setup>
  153. import { x } from './x'
  154. x()
  155. </script>
  156. `)
  157. assertCode(content)
  158. })
  159. test('with minimal spaces', () => {
  160. const { content } = compile(`
  161. <script>
  162. export const n = 1
  163. export default{
  164. some:'option'
  165. }
  166. </script>
  167. <script setup>
  168. import { x } from './x'
  169. x()
  170. </script>
  171. `)
  172. assertCode(content)
  173. })
  174. })
  175. test('export call expression as default', () => {
  176. const { content } = compile(`
  177. <script>
  178. function fn() {
  179. return "hello, world";
  180. }
  181. export default fn();
  182. </script>
  183. <script setup>
  184. console.log('foo')
  185. </script>
  186. `)
  187. assertCode(content)
  188. })
  189. })
  190. describe('imports', () => {
  191. test('should hoist and expose imports', () => {
  192. assertCode(
  193. compile(`<script setup>
  194. import { ref } from 'vue'
  195. import 'foo/css'
  196. </script>`).content
  197. )
  198. })
  199. test('should extract comment for import or type declarations', () => {
  200. assertCode(
  201. compile(`
  202. <script setup>
  203. import a from 'a' // comment
  204. import b from 'b'
  205. </script>
  206. `).content
  207. )
  208. })
  209. // #2740
  210. test('should allow defineProps/Emit at the start of imports', () => {
  211. assertCode(
  212. compile(`<script setup>
  213. import { ref } from 'vue'
  214. defineProps(['foo'])
  215. defineEmits(['bar'])
  216. const r = ref(0)
  217. </script>`).content
  218. )
  219. })
  220. test('dedupe between user & helper', () => {
  221. const { content } = compile(
  222. `
  223. <script setup>
  224. import { ref } from 'vue'
  225. let foo = $ref(1)
  226. </script>
  227. `,
  228. { reactivityTransform: true }
  229. )
  230. assertCode(content)
  231. expect(content).toMatch(`import { ref } from 'vue'`)
  232. })
  233. test('import dedupe between <script> and <script setup>', () => {
  234. const { content } = compile(`
  235. <script>
  236. import { x } from './x'
  237. </script>
  238. <script setup>
  239. import { x } from './x'
  240. x()
  241. </script>
  242. `)
  243. assertCode(content)
  244. expect(content.indexOf(`import { x }`)).toEqual(
  245. content.lastIndexOf(`import { x }`)
  246. )
  247. })
  248. describe('import ref/reactive function from other place', () => {
  249. test('import directly', () => {
  250. const { bindings } = compile(`
  251. <script setup>
  252. import { ref, reactive } from './foo'
  253. const foo = ref(1)
  254. const bar = reactive(1)
  255. </script>
  256. `)
  257. expect(bindings).toStrictEqual({
  258. ref: BindingTypes.SETUP_MAYBE_REF,
  259. reactive: BindingTypes.SETUP_MAYBE_REF,
  260. foo: BindingTypes.SETUP_MAYBE_REF,
  261. bar: BindingTypes.SETUP_MAYBE_REF
  262. })
  263. })
  264. test('import w/ alias', () => {
  265. const { bindings } = compile(`
  266. <script setup>
  267. import { ref as _ref, reactive as _reactive } from './foo'
  268. const foo = ref(1)
  269. const bar = reactive(1)
  270. </script>
  271. `)
  272. expect(bindings).toStrictEqual({
  273. _reactive: BindingTypes.SETUP_MAYBE_REF,
  274. _ref: BindingTypes.SETUP_MAYBE_REF,
  275. foo: BindingTypes.SETUP_MAYBE_REF,
  276. bar: BindingTypes.SETUP_MAYBE_REF
  277. })
  278. })
  279. test('aliased usage before import site', () => {
  280. const { bindings } = compile(`
  281. <script setup>
  282. const bar = x(1)
  283. import { reactive as x } from 'vue'
  284. </script>
  285. `)
  286. expect(bindings).toStrictEqual({
  287. bar: BindingTypes.SETUP_REACTIVE_CONST,
  288. x: BindingTypes.SETUP_CONST
  289. })
  290. })
  291. })
  292. test('should support module string names syntax', () => {
  293. const { content, bindings } = compile(`
  294. <script>
  295. import { "😏" as foo } from './foo'
  296. </script>
  297. <script setup>
  298. import { "😏" as foo } from './foo'
  299. </script>
  300. `)
  301. assertCode(content)
  302. expect(bindings).toStrictEqual({
  303. foo: BindingTypes.SETUP_MAYBE_REF
  304. })
  305. })
  306. })
  307. // in dev mode, declared bindings are returned as an object from setup()
  308. // when using TS, users may import types which should not be returned as
  309. // values, so we need to check import usage in the template to determine
  310. // what to be returned.
  311. describe('dev mode import usage check', () => {
  312. test('components', () => {
  313. const { content } = compile(`
  314. <script setup lang="ts">
  315. import { FooBar, FooBaz, FooQux, foo } from './x'
  316. const fooBar: FooBar = 1
  317. </script>
  318. <template>
  319. <FooBaz></FooBaz>
  320. <foo-qux/>
  321. <foo/>
  322. FooBar
  323. </template>
  324. `)
  325. // FooBar: should not be matched by plain text or incorrect case
  326. // FooBaz: used as PascalCase component
  327. // FooQux: used as kebab-case component
  328. // foo: lowercase component
  329. expect(content).toMatch(
  330. `return { fooBar, get FooBaz() { return FooBaz }, ` +
  331. `get FooQux() { return FooQux }, get foo() { return foo } }`
  332. )
  333. assertCode(content)
  334. })
  335. test('directive', () => {
  336. const { content } = compile(`
  337. <script setup lang="ts">
  338. import { vMyDir } from './x'
  339. </script>
  340. <template>
  341. <div v-my-dir></div>
  342. </template>
  343. `)
  344. expect(content).toMatch(`return { get vMyDir() { return vMyDir } }`)
  345. assertCode(content)
  346. })
  347. test('dynamic arguments', () => {
  348. const { content } = compile(`
  349. <script setup lang="ts">
  350. import { FooBar, foo, bar, unused, baz } from './x'
  351. </script>
  352. <template>
  353. <FooBar #[foo.slotName] />
  354. <FooBar #unused />
  355. <div :[bar.attrName]="15"></div>
  356. <div unused="unused"></div>
  357. <div #[\`item:\${baz.key}\`]="{ value }"></div>
  358. </template>
  359. `)
  360. expect(content).toMatch(
  361. `return { get FooBar() { return FooBar }, get foo() { return foo }, ` +
  362. `get bar() { return bar }, get baz() { return baz } }`
  363. )
  364. assertCode(content)
  365. })
  366. // https://github.com/vuejs/core/issues/4599
  367. test('attribute expressions', () => {
  368. const { content } = compile(`
  369. <script setup lang="ts">
  370. import { bar, baz } from './x'
  371. const cond = true
  372. </script>
  373. <template>
  374. <div :class="[cond ? '' : bar(), 'default']" :style="baz"></div>
  375. </template>
  376. `)
  377. expect(content).toMatch(
  378. `return { cond, get bar() { return bar }, get baz() { return baz } }`
  379. )
  380. assertCode(content)
  381. })
  382. test('vue interpolations', () => {
  383. const { content } = compile(`
  384. <script setup lang="ts">
  385. import { x, y, z, x$y } from './x'
  386. </script>
  387. <template>
  388. <div :id="z + 'y'">{{ x }} {{ yy }} {{ x$y }}</div>
  389. </template>
  390. `)
  391. // x: used in interpolation
  392. // y: should not be matched by {{ yy }} or 'y' in binding exps
  393. // x$y: #4274 should escape special chars when creating Regex
  394. expect(content).toMatch(
  395. `return { get x() { return x }, get z() { return z }, get x$y() { return x$y } }`
  396. )
  397. assertCode(content)
  398. })
  399. // #4340 interpolations in template strings
  400. test('js template string interpolations', () => {
  401. const { content } = compile(`
  402. <script setup lang="ts">
  403. import { VAR, VAR2, VAR3 } from './x'
  404. </script>
  405. <template>
  406. {{ \`\${VAR}VAR2\${VAR3}\` }}
  407. </template>
  408. `)
  409. // VAR2 should not be matched
  410. expect(content).toMatch(
  411. `return { get VAR() { return VAR }, get VAR3() { return VAR3 } }`
  412. )
  413. assertCode(content)
  414. })
  415. // edge case: last tag in template
  416. test('last tag', () => {
  417. const { content } = compile(`
  418. <script setup lang="ts">
  419. import { FooBaz, Last } from './x'
  420. </script>
  421. <template>
  422. <FooBaz></FooBaz>
  423. <Last/>
  424. </template>
  425. `)
  426. expect(content).toMatch(
  427. `return { get FooBaz() { return FooBaz }, get Last() { return Last } }`
  428. )
  429. assertCode(content)
  430. })
  431. test('TS annotations', () => {
  432. const { content } = compile(`
  433. <script setup lang="ts">
  434. import { Foo, Bar, Baz, Qux, Fred } from './x'
  435. const a = 1
  436. function b() {}
  437. </script>
  438. <template>
  439. {{ a as Foo }}
  440. {{ b<Bar>() }}
  441. {{ Baz }}
  442. <Comp v-slot="{ data }: Qux">{{ data }}</Comp>
  443. <div v-for="{ z = x as Qux } in list as Fred"/>
  444. </template>
  445. `)
  446. expect(content).toMatch(`return { a, b, get Baz() { return Baz } }`)
  447. assertCode(content)
  448. })
  449. // vuejs/vue#12591
  450. test('v-on inline statement', () => {
  451. // should not error
  452. compile(`
  453. <script setup lang="ts">
  454. import { foo } from './foo'
  455. </script>
  456. <template>
  457. <div @click="$emit('update:a');"></div>
  458. </template>
  459. `)
  460. })
  461. test('template ref', () => {
  462. const { content } = compile(`
  463. <script setup lang="ts">
  464. import { foo, bar, Baz } from './foo'
  465. </script>
  466. <template>
  467. <div ref="foo"></div>
  468. <div ref=""></div>
  469. <Baz ref="bar" />
  470. </template>
  471. `)
  472. expect(content).toMatch(
  473. 'return { get foo() { return foo }, get bar() { return bar }, get Baz() { return Baz } }'
  474. )
  475. assertCode(content)
  476. })
  477. })
  478. describe('inlineTemplate mode', () => {
  479. test('should work', () => {
  480. const { content } = compile(
  481. `
  482. <script setup>
  483. import { ref } from 'vue'
  484. const count = ref(0)
  485. </script>
  486. <template>
  487. <div>{{ count }}</div>
  488. <div>static</div>
  489. </template>
  490. `,
  491. { inlineTemplate: true }
  492. )
  493. // check snapshot and make sure helper imports and
  494. // hoists are placed correctly.
  495. assertCode(content)
  496. // in inline mode, no need to call expose() since nothing is exposed
  497. // anyway!
  498. expect(content).not.toMatch(`expose()`)
  499. })
  500. test('with defineExpose()', () => {
  501. const { content } = compile(
  502. `
  503. <script setup>
  504. const count = ref(0)
  505. defineExpose({ count })
  506. </script>
  507. `,
  508. { inlineTemplate: true }
  509. )
  510. assertCode(content)
  511. expect(content).toMatch(`setup(__props, { expose: __expose })`)
  512. expect(content).toMatch(`expose({ count })`)
  513. })
  514. test('referencing scope components and directives', () => {
  515. const { content } = compile(
  516. `
  517. <script setup>
  518. import ChildComp from './Child.vue'
  519. import SomeOtherComp from './Other.vue'
  520. import vMyDir from './my-dir'
  521. </script>
  522. <template>
  523. <div v-my-dir></div>
  524. <ChildComp/>
  525. <some-other-comp/>
  526. </template>
  527. `,
  528. { inlineTemplate: true }
  529. )
  530. expect(content).toMatch('[_unref(vMyDir)]')
  531. expect(content).toMatch('_createVNode(ChildComp)')
  532. // kebab-case component support
  533. expect(content).toMatch('_createVNode(SomeOtherComp)')
  534. assertCode(content)
  535. })
  536. test('avoid unref() when necessary', () => {
  537. // function, const, component import
  538. const { content } = compile(
  539. `<script setup>
  540. import { ref } from 'vue'
  541. import Foo, { bar } from './Foo.vue'
  542. import other from './util'
  543. import * as tree from './tree'
  544. const count = ref(0)
  545. const constant = {}
  546. const maybe = foo()
  547. let lett = 1
  548. function fn() {}
  549. </script>
  550. <template>
  551. <Foo>{{ bar }}</Foo>
  552. <div @click="fn">{{ count }} {{ constant }} {{ maybe }} {{ lett }} {{ other }}</div>
  553. {{ tree.foo() }}
  554. </template>
  555. `,
  556. { inlineTemplate: true }
  557. )
  558. // no need to unref vue component import
  559. expect(content).toMatch(`createVNode(Foo,`)
  560. // #2699 should unref named imports from .vue
  561. expect(content).toMatch(`unref(bar)`)
  562. // should unref other imports
  563. expect(content).toMatch(`unref(other)`)
  564. // no need to unref constant literals
  565. expect(content).not.toMatch(`unref(constant)`)
  566. // should directly use .value for known refs
  567. expect(content).toMatch(`count.value`)
  568. // should unref() on const bindings that may be refs
  569. expect(content).toMatch(`unref(maybe)`)
  570. // should unref() on let bindings
  571. expect(content).toMatch(`unref(lett)`)
  572. // no need to unref namespace import (this also preserves tree-shaking)
  573. expect(content).toMatch(`tree.foo()`)
  574. // no need to unref function declarations
  575. expect(content).toMatch(`{ onClick: fn }`)
  576. // no need to mark constant fns in patch flag
  577. expect(content).not.toMatch(`PROPS`)
  578. assertCode(content)
  579. })
  580. test('v-model codegen', () => {
  581. const { content } = compile(
  582. `<script setup>
  583. import { ref } from 'vue'
  584. const count = ref(0)
  585. const maybe = foo()
  586. let lett = 1
  587. </script>
  588. <template>
  589. <input v-model="count">
  590. <input v-model="maybe">
  591. <input v-model="lett">
  592. </template>
  593. `,
  594. { inlineTemplate: true }
  595. )
  596. // known const ref: set value
  597. expect(content).toMatch(`(count).value = $event`)
  598. // const but maybe ref: assign if ref, otherwise do nothing
  599. expect(content).toMatch(`_isRef(maybe) ? (maybe).value = $event : null`)
  600. // let: handle both cases
  601. expect(content).toMatch(
  602. `_isRef(lett) ? (lett).value = $event : lett = $event`
  603. )
  604. assertCode(content)
  605. })
  606. test('v-model should not generate ref assignment code for non-setup bindings', () => {
  607. const { content } = compile(
  608. `<script setup>
  609. import { ref } from 'vue'
  610. const count = ref(0)
  611. </script>
  612. <script>
  613. export default {
  614. data() { return { foo: 123 } }
  615. }
  616. </script>
  617. <template>
  618. <input v-model="foo">
  619. </template>
  620. `,
  621. { inlineTemplate: true }
  622. )
  623. expect(content).not.toMatch(`_isRef(foo)`)
  624. })
  625. test('template assignment expression codegen', () => {
  626. const { content } = compile(
  627. `<script setup>
  628. import { ref } from 'vue'
  629. const count = ref(0)
  630. const maybe = foo()
  631. let lett = 1
  632. let v = ref(1)
  633. </script>
  634. <template>
  635. <div @click="count = 1"/>
  636. <div @click="maybe = count"/>
  637. <div @click="lett = count"/>
  638. <div @click="v += 1"/>
  639. <div @click="v -= 1"/>
  640. <div @click="() => {
  641. let a = '' + lett
  642. v = a
  643. }"/>
  644. <div @click="() => {
  645. // nested scopes
  646. (()=>{
  647. let x = a
  648. (()=>{
  649. let z = x
  650. let z2 = z
  651. })
  652. let lz = z
  653. })
  654. v = a
  655. }"/>
  656. </template>
  657. `,
  658. { inlineTemplate: true }
  659. )
  660. // known const ref: set value
  661. expect(content).toMatch(`count.value = 1`)
  662. // const but maybe ref: only assign after check
  663. expect(content).toMatch(`maybe.value = count.value`)
  664. // let: handle both cases
  665. expect(content).toMatch(
  666. `_isRef(lett) ? lett.value = count.value : lett = count.value`
  667. )
  668. expect(content).toMatch(`_isRef(v) ? v.value += 1 : v += 1`)
  669. expect(content).toMatch(`_isRef(v) ? v.value -= 1 : v -= 1`)
  670. expect(content).toMatch(`_isRef(v) ? v.value = a : v = a`)
  671. expect(content).toMatch(`_isRef(v) ? v.value = _ctx.a : v = _ctx.a`)
  672. assertCode(content)
  673. })
  674. test('template update expression codegen', () => {
  675. const { content } = compile(
  676. `<script setup>
  677. import { ref } from 'vue'
  678. const count = ref(0)
  679. const maybe = foo()
  680. let lett = 1
  681. </script>
  682. <template>
  683. <div @click="count++"/>
  684. <div @click="--count"/>
  685. <div @click="maybe++"/>
  686. <div @click="--maybe"/>
  687. <div @click="lett++"/>
  688. <div @click="--lett"/>
  689. </template>
  690. `,
  691. { inlineTemplate: true }
  692. )
  693. // known const ref: set value
  694. expect(content).toMatch(`count.value++`)
  695. expect(content).toMatch(`--count.value`)
  696. // const but maybe ref (non-ref case ignored)
  697. expect(content).toMatch(`maybe.value++`)
  698. expect(content).toMatch(`--maybe.value`)
  699. // let: handle both cases
  700. expect(content).toMatch(`_isRef(lett) ? lett.value++ : lett++`)
  701. expect(content).toMatch(`_isRef(lett) ? --lett.value : --lett`)
  702. assertCode(content)
  703. })
  704. test('template destructure assignment codegen', () => {
  705. const { content } = compile(
  706. `<script setup>
  707. import { ref } from 'vue'
  708. const val = {}
  709. const count = ref(0)
  710. const maybe = foo()
  711. let lett = 1
  712. </script>
  713. <template>
  714. <div @click="({ count } = val)"/>
  715. <div @click="[maybe] = val"/>
  716. <div @click="({ lett } = val)"/>
  717. </template>
  718. `,
  719. { inlineTemplate: true }
  720. )
  721. // known const ref: set value
  722. expect(content).toMatch(`({ count: count.value } = val)`)
  723. // const but maybe ref (non-ref case ignored)
  724. expect(content).toMatch(`[maybe.value] = val`)
  725. // let: assumes non-ref
  726. expect(content).toMatch(`{ lett: lett } = val`)
  727. assertCode(content)
  728. })
  729. test('ssr codegen', () => {
  730. const { content } = compile(
  731. `
  732. <script setup>
  733. import { ref } from 'vue'
  734. const count = ref(0)
  735. </script>
  736. <template>
  737. <div>{{ count }}</div>
  738. <div>static</div>
  739. </template>
  740. <style>
  741. div { color: v-bind(count) }
  742. </style>
  743. `,
  744. {
  745. inlineTemplate: true,
  746. templateOptions: {
  747. ssr: true
  748. }
  749. }
  750. )
  751. expect(content).toMatch(`\n __ssrInlineRender: true,\n`)
  752. expect(content).toMatch(`return (_ctx, _push`)
  753. expect(content).toMatch(`ssrInterpolate`)
  754. expect(content).not.toMatch(`useCssVars`)
  755. expect(content).toMatch(`"--${mockId}-count": (count.value)`)
  756. assertCode(content)
  757. })
  758. test('the v-for wrapped in parentheses can be correctly parsed & inline is false', () => {
  759. expect(() =>
  760. compile(
  761. `
  762. <script setup lang="ts">
  763. import { ref } from 'vue'
  764. const stacks = ref([])
  765. </script>
  766. <template>
  767. <div v-for="({ file: efile }) of stacks"></div>
  768. </template>
  769. `,
  770. {
  771. inlineTemplate: false
  772. }
  773. )
  774. ).not.toThrowError()
  775. })
  776. })
  777. describe('with TypeScript', () => {
  778. test('hoist type declarations', () => {
  779. const { content } = compile(`
  780. <script setup lang="ts">
  781. export interface Foo {}
  782. type Bar = {}
  783. </script>`)
  784. assertCode(content)
  785. })
  786. test('runtime Enum', () => {
  787. const { content, bindings } = compile(
  788. `<script setup lang="ts">
  789. enum Foo { A = 123 }
  790. </script>`
  791. )
  792. assertCode(content)
  793. expect(bindings).toStrictEqual({
  794. Foo: BindingTypes.LITERAL_CONST
  795. })
  796. })
  797. test('runtime Enum in normal script', () => {
  798. const { content, bindings } = compile(
  799. `<script lang="ts">
  800. export enum D { D = "D" }
  801. const enum C { C = "C" }
  802. enum B { B = "B" }
  803. </script>
  804. <script setup lang="ts">
  805. enum Foo { A = 123 }
  806. </script>`
  807. )
  808. assertCode(content)
  809. expect(bindings).toStrictEqual({
  810. D: BindingTypes.LITERAL_CONST,
  811. C: BindingTypes.LITERAL_CONST,
  812. B: BindingTypes.LITERAL_CONST,
  813. Foo: BindingTypes.LITERAL_CONST
  814. })
  815. })
  816. test('const Enum', () => {
  817. const { content, bindings } = compile(
  818. `<script setup lang="ts">
  819. const enum Foo { A = 123 }
  820. </script>`,
  821. { hoistStatic: true }
  822. )
  823. assertCode(content)
  824. expect(bindings).toStrictEqual({
  825. Foo: BindingTypes.LITERAL_CONST
  826. })
  827. })
  828. test('import type', () => {
  829. const { content } = compile(
  830. `<script setup lang="ts">
  831. import type { Foo } from './main.ts'
  832. import { type Bar, Baz } from './main.ts'
  833. </script>`
  834. )
  835. expect(content).toMatch(`return { get Baz() { return Baz } }`)
  836. assertCode(content)
  837. })
  838. })
  839. describe('async/await detection', () => {
  840. function assertAwaitDetection(code: string, shouldAsync = true) {
  841. const { content } = compile(`<script setup>${code}</script>`, {
  842. reactivityTransform: true
  843. })
  844. if (shouldAsync) {
  845. expect(content).toMatch(`let __temp, __restore`)
  846. }
  847. expect(content).toMatch(`${shouldAsync ? `async ` : ``}setup(`)
  848. assertCode(content)
  849. return content
  850. }
  851. test('expression statement', () => {
  852. assertAwaitDetection(`await foo`)
  853. })
  854. test('variable', () => {
  855. assertAwaitDetection(`const a = 1 + (await foo)`)
  856. })
  857. test('ref', () => {
  858. assertAwaitDetection(`let a = $ref(1 + (await foo))`)
  859. })
  860. // #4448
  861. test('nested await', () => {
  862. assertAwaitDetection(`await (await foo)`)
  863. assertAwaitDetection(`await ((await foo))`)
  864. assertAwaitDetection(`await (await (await foo))`)
  865. })
  866. // should prepend semicolon
  867. test('nested leading await in expression statement', () => {
  868. const code = assertAwaitDetection(`foo()\nawait 1 + await 2`)
  869. expect(code).toMatch(`foo()\n;(`)
  870. })
  871. // #4596 should NOT prepend semicolon
  872. test('single line conditions', () => {
  873. const code = assertAwaitDetection(`if (false) await foo()`)
  874. expect(code).not.toMatch(`if (false) ;(`)
  875. })
  876. test('nested statements', () => {
  877. assertAwaitDetection(`if (ok) { await foo } else { await bar }`)
  878. })
  879. test('multiple `if` nested statements', () => {
  880. assertAwaitDetection(`if (ok) {
  881. let a = 'foo'
  882. await 0 + await 1
  883. await 2
  884. } else if (a) {
  885. await 10
  886. if (b) {
  887. await 0 + await 1
  888. } else {
  889. let a = 'foo'
  890. await 2
  891. }
  892. if (b) {
  893. await 3
  894. await 4
  895. }
  896. } else {
  897. await 5
  898. }`)
  899. })
  900. test('multiple `if while` nested statements', () => {
  901. assertAwaitDetection(`if (ok) {
  902. while (d) {
  903. await 5
  904. }
  905. while (d) {
  906. await 5
  907. await 6
  908. if (c) {
  909. let f = 10
  910. 10 + await 7
  911. } else {
  912. await 8
  913. await 9
  914. }
  915. }
  916. }`)
  917. })
  918. test('multiple `if for` nested statements', () => {
  919. assertAwaitDetection(`if (ok) {
  920. for (let a of [1,2,3]) {
  921. await a
  922. }
  923. for (let a of [1,2,3]) {
  924. await a
  925. await a
  926. }
  927. }`)
  928. })
  929. test('should ignore await inside functions', () => {
  930. // function declaration
  931. assertAwaitDetection(`async function foo() { await bar }`, false)
  932. // function expression
  933. assertAwaitDetection(`const foo = async () => { await bar }`, false)
  934. // object method
  935. assertAwaitDetection(`const obj = { async method() { await bar }}`, false)
  936. // class method
  937. assertAwaitDetection(
  938. `const cls = class Foo { async method() { await bar }}`,
  939. false
  940. )
  941. })
  942. })
  943. describe('errors', () => {
  944. test('<script> and <script setup> must have same lang', () => {
  945. expect(() =>
  946. compile(`<script>foo()</script><script setup lang="ts">bar()</script>`)
  947. ).toThrow(`<script> and <script setup> must have the same language type`)
  948. })
  949. const moduleErrorMsg = `cannot contain ES module exports`
  950. test('non-type named exports', () => {
  951. expect(() =>
  952. compile(`<script setup>
  953. export const a = 1
  954. </script>`)
  955. ).toThrow(moduleErrorMsg)
  956. expect(() =>
  957. compile(`<script setup>
  958. export * from './foo'
  959. </script>`)
  960. ).toThrow(moduleErrorMsg)
  961. expect(() =>
  962. compile(`<script setup>
  963. const bar = 1
  964. export { bar as default }
  965. </script>`)
  966. ).toThrow(moduleErrorMsg)
  967. })
  968. test('defineProps/Emit() referencing local var', () => {
  969. expect(() =>
  970. compile(`<script setup>
  971. let bar = 1
  972. defineProps({
  973. foo: {
  974. default: () => bar
  975. }
  976. })
  977. </script>`)
  978. ).toThrow(`cannot reference locally declared variables`)
  979. expect(() =>
  980. compile(`<script setup>
  981. let bar = 'hello'
  982. defineEmits([bar])
  983. </script>`)
  984. ).toThrow(`cannot reference locally declared variables`)
  985. // #4644
  986. expect(() =>
  987. compile(`
  988. <script>const bar = 1</script>
  989. <script setup>
  990. defineProps({
  991. foo: {
  992. default: () => bar
  993. }
  994. })
  995. </script>`)
  996. ).not.toThrow(`cannot reference locally declared variables`)
  997. })
  998. test('should allow defineProps/Emit() referencing scope var', () => {
  999. assertCode(
  1000. compile(`<script setup>
  1001. const bar = 1
  1002. defineProps({
  1003. foo: {
  1004. default: bar => bar + 1
  1005. }
  1006. })
  1007. defineEmits({
  1008. foo: bar => bar > 1
  1009. })
  1010. </script>`).content
  1011. )
  1012. })
  1013. test('should allow defineProps/Emit() referencing imported binding', () => {
  1014. assertCode(
  1015. compile(`<script setup>
  1016. import { bar } from './bar'
  1017. defineProps({
  1018. foo: {
  1019. default: () => bar
  1020. }
  1021. })
  1022. defineEmits({
  1023. foo: () => bar > 1
  1024. })
  1025. </script>`).content
  1026. )
  1027. })
  1028. })
  1029. })
  1030. describe('SFC analyze <script> bindings', () => {
  1031. it('can parse decorators syntax in typescript block', () => {
  1032. const { scriptAst } = compile(`
  1033. <script lang="ts">
  1034. import { Options, Vue } from 'vue-class-component';
  1035. @Options({
  1036. components: {
  1037. HelloWorld,
  1038. },
  1039. props: ['foo', 'bar']
  1040. })
  1041. export default class Home extends Vue {}
  1042. </script>
  1043. `)
  1044. expect(scriptAst).toBeDefined()
  1045. })
  1046. it('recognizes props array declaration', () => {
  1047. const { bindings } = compile(`
  1048. <script>
  1049. export default {
  1050. props: ['foo', 'bar']
  1051. }
  1052. </script>
  1053. `)
  1054. expect(bindings).toStrictEqual({
  1055. foo: BindingTypes.PROPS,
  1056. bar: BindingTypes.PROPS
  1057. })
  1058. expect(bindings!.__isScriptSetup).toBe(false)
  1059. })
  1060. it('recognizes props object declaration', () => {
  1061. const { bindings } = compile(`
  1062. <script>
  1063. export default {
  1064. props: {
  1065. foo: String,
  1066. bar: {
  1067. type: String,
  1068. },
  1069. baz: null,
  1070. qux: [String, Number]
  1071. }
  1072. }
  1073. </script>
  1074. `)
  1075. expect(bindings).toStrictEqual({
  1076. foo: BindingTypes.PROPS,
  1077. bar: BindingTypes.PROPS,
  1078. baz: BindingTypes.PROPS,
  1079. qux: BindingTypes.PROPS
  1080. })
  1081. expect(bindings!.__isScriptSetup).toBe(false)
  1082. })
  1083. it('recognizes setup return', () => {
  1084. const { bindings } = compile(`
  1085. <script>
  1086. const bar = 2
  1087. export default {
  1088. setup() {
  1089. return {
  1090. foo: 1,
  1091. bar
  1092. }
  1093. }
  1094. }
  1095. </script>
  1096. `)
  1097. expect(bindings).toStrictEqual({
  1098. foo: BindingTypes.SETUP_MAYBE_REF,
  1099. bar: BindingTypes.SETUP_MAYBE_REF
  1100. })
  1101. expect(bindings!.__isScriptSetup).toBe(false)
  1102. })
  1103. it('recognizes exported vars', () => {
  1104. const { bindings } = compile(`
  1105. <script>
  1106. export const foo = 2
  1107. </script>
  1108. <script setup>
  1109. console.log(foo)
  1110. </script>
  1111. `)
  1112. expect(bindings).toStrictEqual({
  1113. foo: BindingTypes.LITERAL_CONST
  1114. })
  1115. })
  1116. it('recognizes async setup return', () => {
  1117. const { bindings } = compile(`
  1118. <script>
  1119. const bar = 2
  1120. export default {
  1121. async setup() {
  1122. return {
  1123. foo: 1,
  1124. bar
  1125. }
  1126. }
  1127. }
  1128. </script>
  1129. `)
  1130. expect(bindings).toStrictEqual({
  1131. foo: BindingTypes.SETUP_MAYBE_REF,
  1132. bar: BindingTypes.SETUP_MAYBE_REF
  1133. })
  1134. expect(bindings!.__isScriptSetup).toBe(false)
  1135. })
  1136. it('recognizes data return', () => {
  1137. const { bindings } = compile(`
  1138. <script>
  1139. const bar = 2
  1140. export default {
  1141. data() {
  1142. return {
  1143. foo: null,
  1144. bar
  1145. }
  1146. }
  1147. }
  1148. </script>
  1149. `)
  1150. expect(bindings).toStrictEqual({
  1151. foo: BindingTypes.DATA,
  1152. bar: BindingTypes.DATA
  1153. })
  1154. })
  1155. it('recognizes methods', () => {
  1156. const { bindings } = compile(`
  1157. <script>
  1158. export default {
  1159. methods: {
  1160. foo() {}
  1161. }
  1162. }
  1163. </script>
  1164. `)
  1165. expect(bindings).toStrictEqual({ foo: BindingTypes.OPTIONS })
  1166. })
  1167. it('recognizes computeds', () => {
  1168. const { bindings } = compile(`
  1169. <script>
  1170. export default {
  1171. computed: {
  1172. foo() {},
  1173. bar: {
  1174. get() {},
  1175. set() {},
  1176. }
  1177. }
  1178. }
  1179. </script>
  1180. `)
  1181. expect(bindings).toStrictEqual({
  1182. foo: BindingTypes.OPTIONS,
  1183. bar: BindingTypes.OPTIONS
  1184. })
  1185. })
  1186. it('recognizes injections array declaration', () => {
  1187. const { bindings } = compile(`
  1188. <script>
  1189. export default {
  1190. inject: ['foo', 'bar']
  1191. }
  1192. </script>
  1193. `)
  1194. expect(bindings).toStrictEqual({
  1195. foo: BindingTypes.OPTIONS,
  1196. bar: BindingTypes.OPTIONS
  1197. })
  1198. })
  1199. it('recognizes injections object declaration', () => {
  1200. const { bindings } = compile(`
  1201. <script>
  1202. export default {
  1203. inject: {
  1204. foo: {},
  1205. bar: {},
  1206. }
  1207. }
  1208. </script>
  1209. `)
  1210. expect(bindings).toStrictEqual({
  1211. foo: BindingTypes.OPTIONS,
  1212. bar: BindingTypes.OPTIONS
  1213. })
  1214. })
  1215. it('works for mixed bindings', () => {
  1216. const { bindings } = compile(`
  1217. <script>
  1218. export default {
  1219. inject: ['foo'],
  1220. props: {
  1221. bar: String,
  1222. },
  1223. setup() {
  1224. return {
  1225. baz: null,
  1226. }
  1227. },
  1228. data() {
  1229. return {
  1230. qux: null
  1231. }
  1232. },
  1233. methods: {
  1234. quux() {}
  1235. },
  1236. computed: {
  1237. quuz() {}
  1238. }
  1239. }
  1240. </script>
  1241. `)
  1242. expect(bindings).toStrictEqual({
  1243. foo: BindingTypes.OPTIONS,
  1244. bar: BindingTypes.PROPS,
  1245. baz: BindingTypes.SETUP_MAYBE_REF,
  1246. qux: BindingTypes.DATA,
  1247. quux: BindingTypes.OPTIONS,
  1248. quuz: BindingTypes.OPTIONS
  1249. })
  1250. })
  1251. it('works for script setup', () => {
  1252. const { bindings } = compile(`
  1253. <script setup>
  1254. import { ref as r } from 'vue'
  1255. defineProps({
  1256. foo: String
  1257. })
  1258. const a = r(1)
  1259. let b = 2
  1260. const c = 3
  1261. const { d } = someFoo()
  1262. let { e } = someBar()
  1263. </script>
  1264. `)
  1265. expect(bindings).toStrictEqual({
  1266. r: BindingTypes.SETUP_CONST,
  1267. a: BindingTypes.SETUP_REF,
  1268. b: BindingTypes.SETUP_LET,
  1269. c: BindingTypes.LITERAL_CONST,
  1270. d: BindingTypes.SETUP_MAYBE_REF,
  1271. e: BindingTypes.SETUP_LET,
  1272. foo: BindingTypes.PROPS
  1273. })
  1274. })
  1275. describe('auto name inference', () => {
  1276. test('basic', () => {
  1277. const { content } = compile(
  1278. `<script setup>const a = 1</script>
  1279. <template>{{ a }}</template>`,
  1280. undefined,
  1281. {
  1282. filename: 'FooBar.vue'
  1283. }
  1284. )
  1285. expect(content).toMatch(`export default {
  1286. __name: 'FooBar'`)
  1287. assertCode(content)
  1288. })
  1289. test('do not overwrite manual name (object)', () => {
  1290. const { content } = compile(
  1291. `<script>
  1292. export default {
  1293. name: 'Baz'
  1294. }
  1295. </script>
  1296. <script setup>const a = 1</script>
  1297. <template>{{ a }}</template>`,
  1298. undefined,
  1299. {
  1300. filename: 'FooBar.vue'
  1301. }
  1302. )
  1303. expect(content).not.toMatch(`name: 'FooBar'`)
  1304. expect(content).toMatch(`name: 'Baz'`)
  1305. assertCode(content)
  1306. })
  1307. test('do not overwrite manual name (call)', () => {
  1308. const { content } = compile(
  1309. `<script>
  1310. import { defineComponent } from 'vue'
  1311. export default defineComponent({
  1312. name: 'Baz'
  1313. })
  1314. </script>
  1315. <script setup>const a = 1</script>
  1316. <template>{{ a }}</template>`,
  1317. undefined,
  1318. {
  1319. filename: 'FooBar.vue'
  1320. }
  1321. )
  1322. expect(content).not.toMatch(`name: 'FooBar'`)
  1323. expect(content).toMatch(`name: 'Baz'`)
  1324. assertCode(content)
  1325. })
  1326. })
  1327. })
  1328. describe('SFC genDefaultAs', () => {
  1329. test('normal <script> only', () => {
  1330. const { content } = compile(
  1331. `<script>
  1332. export default {}
  1333. </script>`,
  1334. {
  1335. genDefaultAs: '_sfc_'
  1336. }
  1337. )
  1338. expect(content).not.toMatch('export default')
  1339. expect(content).toMatch(`const _sfc_ = {}`)
  1340. assertCode(content)
  1341. })
  1342. test('normal <script> w/ cssVars', () => {
  1343. const { content } = compile(
  1344. `<script>
  1345. export default {}
  1346. </script>
  1347. <style>
  1348. .foo { color: v-bind(x) }
  1349. </style>`,
  1350. {
  1351. genDefaultAs: '_sfc_'
  1352. }
  1353. )
  1354. expect(content).not.toMatch('export default')
  1355. expect(content).not.toMatch('__default__')
  1356. expect(content).toMatch(`const _sfc_ = {}`)
  1357. assertCode(content)
  1358. })
  1359. test('<script> + <script setup>', () => {
  1360. const { content } = compile(
  1361. `<script>
  1362. export default {}
  1363. </script>
  1364. <script setup>
  1365. const a = 1
  1366. </script>`,
  1367. {
  1368. genDefaultAs: '_sfc_'
  1369. }
  1370. )
  1371. expect(content).not.toMatch('export default')
  1372. expect(content).toMatch(
  1373. `const _sfc_ = /*#__PURE__*/Object.assign(__default__`
  1374. )
  1375. assertCode(content)
  1376. })
  1377. test('<script> + <script setup>', () => {
  1378. const { content } = compile(
  1379. `<script>
  1380. export default {}
  1381. </script>
  1382. <script setup>
  1383. const a = 1
  1384. </script>`,
  1385. {
  1386. genDefaultAs: '_sfc_'
  1387. }
  1388. )
  1389. expect(content).not.toMatch('export default')
  1390. expect(content).toMatch(
  1391. `const _sfc_ = /*#__PURE__*/Object.assign(__default__`
  1392. )
  1393. assertCode(content)
  1394. })
  1395. test('<script setup> only', () => {
  1396. const { content } = compile(
  1397. `<script setup>
  1398. const a = 1
  1399. </script>`,
  1400. {
  1401. genDefaultAs: '_sfc_'
  1402. }
  1403. )
  1404. expect(content).not.toMatch('export default')
  1405. expect(content).toMatch(`const _sfc_ = {\n setup`)
  1406. assertCode(content)
  1407. })
  1408. test('<script setup> only w/ ts', () => {
  1409. const { content } = compile(
  1410. `<script setup lang="ts">
  1411. const a = 1
  1412. </script>`,
  1413. {
  1414. genDefaultAs: '_sfc_'
  1415. }
  1416. )
  1417. expect(content).not.toMatch('export default')
  1418. expect(content).toMatch(`const _sfc_ = /*#__PURE__*/_defineComponent(`)
  1419. assertCode(content)
  1420. })
  1421. test('<script> + <script setup> w/ ts', () => {
  1422. const { content } = compile(
  1423. `<script lang="ts">
  1424. export default {}
  1425. </script>
  1426. <script setup lang="ts">
  1427. const a = 1
  1428. </script>`,
  1429. {
  1430. genDefaultAs: '_sfc_'
  1431. }
  1432. )
  1433. expect(content).not.toMatch('export default')
  1434. expect(content).toMatch(
  1435. `const _sfc_ = /*#__PURE__*/_defineComponent({\n ...__default__`
  1436. )
  1437. assertCode(content)
  1438. })
  1439. test('binding type for edge cases', () => {
  1440. const { bindings } = compile(
  1441. `<script setup lang="ts">
  1442. import { toRef } from 'vue'
  1443. const props = defineProps<{foo: string}>()
  1444. const foo = toRef(() => props.foo)
  1445. </script>`
  1446. )
  1447. expect(bindings).toStrictEqual({
  1448. toRef: BindingTypes.SETUP_CONST,
  1449. props: BindingTypes.SETUP_REACTIVE_CONST,
  1450. foo: BindingTypes.SETUP_REF
  1451. })
  1452. })
  1453. })