fix(compiler-sfc): <script> after <script setup> the script content not end with \\n
This commit is contained in:
parent
242914d938
commit
3b7b107120
@ -17,7 +17,7 @@ exports[`SFC analyze <script> bindings auto name inference do not overwrite manu
|
||||
const __default__ = defineComponent({
|
||||
name: 'Baz'
|
||||
})
|
||||
|
||||
|
||||
export default /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
@ -32,7 +32,7 @@ exports[`SFC analyze <script> bindings auto name inference do not overwrite manu
|
||||
"const __default__ = {
|
||||
name: 'Baz'
|
||||
}
|
||||
|
||||
|
||||
export default /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
@ -43,19 +43,34 @@ return { a }
|
||||
})"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> <script> after <script setup> the script content not end with \`\\n\` 1`] = `
|
||||
"const n = 1
|
||||
import { x } from './x'
|
||||
|
||||
export default {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
return { n, x }
|
||||
}
|
||||
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`SFC compile <script setup> <script> and <script setup> co-usage script first 1`] = `
|
||||
"import { x } from './x'
|
||||
|
||||
|
||||
export const n = 1
|
||||
|
||||
const __default__ = {}
|
||||
|
||||
|
||||
export default /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
x()
|
||||
|
||||
|
||||
return { n, x }
|
||||
}
|
||||
|
||||
@ -66,13 +81,13 @@ exports[`SFC compile <script setup> <script> and <script setup> co-usage script
|
||||
"export const n = 1
|
||||
const __default__ = {}
|
||||
import { x } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
x()
|
||||
|
||||
|
||||
return { n, x }
|
||||
}
|
||||
|
||||
@ -86,14 +101,14 @@ exports[`SFC compile <script setup> <script> and <script setup> co-usage script
|
||||
name: \\"test\\"
|
||||
}
|
||||
import { x } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
...__default__,
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
x()
|
||||
|
||||
|
||||
return { x }
|
||||
}
|
||||
|
||||
@ -103,17 +118,17 @@ return { x }
|
||||
exports[`SFC compile <script setup> <script> and <script setup> co-usage script setup first, named default export 1`] = `
|
||||
"export const n = 1
|
||||
const def = {}
|
||||
|
||||
|
||||
|
||||
|
||||
const __default__ = def
|
||||
import { x } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
x()
|
||||
|
||||
|
||||
return { n, def, x }
|
||||
}
|
||||
|
||||
@ -122,18 +137,18 @@ return { n, def, x }
|
||||
|
||||
exports[`SFC compile <script setup> <script> and <script setup> co-usage spaces in ExportDefaultDeclaration node with many spaces and newline 1`] = `
|
||||
"import { x } from './x'
|
||||
|
||||
|
||||
export const n = 1
|
||||
const __default__ = {
|
||||
some:'option'
|
||||
}
|
||||
|
||||
|
||||
export default /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
x()
|
||||
|
||||
|
||||
return { n, x }
|
||||
}
|
||||
|
||||
@ -142,18 +157,18 @@ return { n, x }
|
||||
|
||||
exports[`SFC compile <script setup> <script> and <script setup> co-usage spaces in ExportDefaultDeclaration node with minimal spaces 1`] = `
|
||||
"import { x } from './x'
|
||||
|
||||
|
||||
export const n = 1
|
||||
const __default__ = {
|
||||
some:'option'
|
||||
}
|
||||
|
||||
|
||||
export default /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
x()
|
||||
|
||||
|
||||
return { n, x }
|
||||
}
|
||||
|
||||
@ -414,7 +429,7 @@ exports[`SFC compile <script setup> binding analysis for destructure 1`] = `
|
||||
expose();
|
||||
|
||||
const { foo, b: bar, ['x' + 'y']: baz, x: { y, zz: { z }}} = {}
|
||||
|
||||
|
||||
return { foo, bar, baz, y, z }
|
||||
}
|
||||
|
||||
@ -449,7 +464,7 @@ return { }
|
||||
|
||||
exports[`SFC compile <script setup> defineProps w/ external definition 1`] = `
|
||||
"import { propsModel } from './props'
|
||||
|
||||
|
||||
export default {
|
||||
props: propsModel,
|
||||
setup(__props, { expose }) {
|
||||
@ -457,8 +472,8 @@ export default {
|
||||
|
||||
const props = __props
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { props, propsModel }
|
||||
}
|
||||
|
||||
@ -467,7 +482,7 @@ return { props, propsModel }
|
||||
|
||||
exports[`SFC compile <script setup> defineProps w/ leading code 1`] = `
|
||||
"import { x } from './x'
|
||||
|
||||
|
||||
export default {
|
||||
props: {},
|
||||
setup(__props, { expose }) {
|
||||
@ -475,7 +490,7 @@ export default {
|
||||
|
||||
const props = __props
|
||||
|
||||
|
||||
|
||||
return { props, x }
|
||||
}
|
||||
|
||||
@ -510,8 +525,8 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
|
||||
|
||||
const props = __props
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { props, emit }
|
||||
}
|
||||
|
||||
@ -528,7 +543,7 @@ exports[`SFC compile <script setup> defineProps/defineEmits in multi-variable de
|
||||
const props = __props
|
||||
|
||||
const a = 1;
|
||||
|
||||
|
||||
return { props, a, emit }
|
||||
}
|
||||
|
||||
@ -538,14 +553,14 @@ return { props, a, emit }
|
||||
exports[`SFC compile <script setup> dev mode import usage check TS annotations 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import { Foo, Bar, Baz } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
const a = 1
|
||||
function b() {}
|
||||
|
||||
|
||||
return { a, b, Baz }
|
||||
}
|
||||
|
||||
@ -555,13 +570,13 @@ return { a, b, Baz }
|
||||
exports[`SFC compile <script setup> dev mode import usage check attribute expressions 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import { bar, baz } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
const cond = true
|
||||
|
||||
|
||||
return { cond, bar, baz }
|
||||
}
|
||||
|
||||
@ -571,13 +586,13 @@ return { cond, bar, baz }
|
||||
exports[`SFC compile <script setup> dev mode import usage check components 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import { FooBar, FooBaz, FooQux, foo } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
const fooBar: FooBar = 1
|
||||
|
||||
|
||||
return { fooBar, FooBaz, FooQux, foo }
|
||||
}
|
||||
|
||||
@ -587,12 +602,12 @@ return { fooBar, FooBaz, FooQux, foo }
|
||||
exports[`SFC compile <script setup> dev mode import usage check directive 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import { vMyDir } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { vMyDir }
|
||||
}
|
||||
|
||||
@ -602,12 +617,12 @@ return { vMyDir }
|
||||
exports[`SFC compile <script setup> dev mode import usage check js template string interpolations 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import { VAR, VAR2, VAR3 } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { VAR, VAR3 }
|
||||
}
|
||||
|
||||
@ -617,12 +632,12 @@ return { VAR, VAR3 }
|
||||
exports[`SFC compile <script setup> dev mode import usage check last tag 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import { FooBaz, Last } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { FooBaz, Last }
|
||||
}
|
||||
|
||||
@ -632,12 +647,12 @@ return { FooBaz, Last }
|
||||
exports[`SFC compile <script setup> dev mode import usage check vue interpolations 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import { x, y, z, x$y } from './x'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { x, z, x$y }
|
||||
}
|
||||
|
||||
@ -646,7 +661,7 @@ return { x, z, x$y }
|
||||
|
||||
exports[`SFC compile <script setup> errors should allow defineProps/Emit() referencing imported binding 1`] = `
|
||||
"import { bar } from './bar'
|
||||
|
||||
|
||||
export default {
|
||||
props: {
|
||||
foo: {
|
||||
@ -659,9 +674,9 @@ export default {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { bar }
|
||||
}
|
||||
|
||||
@ -682,9 +697,9 @@ exports[`SFC compile <script setup> errors should allow defineProps/Emit() refer
|
||||
expose();
|
||||
|
||||
const bar = 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { bar }
|
||||
}
|
||||
|
||||
@ -694,13 +709,13 @@ return { bar }
|
||||
exports[`SFC compile <script setup> imports dedupe between user & helper 1`] = `
|
||||
"import { ref as _ref } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
let foo = _ref(1)
|
||||
|
||||
|
||||
return { foo, ref }
|
||||
}
|
||||
|
||||
@ -709,13 +724,13 @@ return { foo, ref }
|
||||
|
||||
exports[`SFC compile <script setup> imports import dedupe between <script> and <script setup> 1`] = `
|
||||
"import { x } from './x'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
x()
|
||||
|
||||
|
||||
return { x }
|
||||
}
|
||||
|
||||
@ -724,17 +739,17 @@ return { x }
|
||||
|
||||
exports[`SFC compile <script setup> imports should allow defineProps/Emit at the start of imports 1`] = `
|
||||
"import { ref } from 'vue'
|
||||
|
||||
|
||||
export default {
|
||||
props: ['foo'],
|
||||
emits: ['bar'],
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const r = ref(0)
|
||||
|
||||
|
||||
return { r, ref }
|
||||
}
|
||||
|
||||
@ -744,12 +759,12 @@ return { r, ref }
|
||||
exports[`SFC compile <script setup> imports should extract comment for import or type declarations 1`] = `
|
||||
"import a from 'a' // comment
|
||||
import b from 'b'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { a, b }
|
||||
}
|
||||
|
||||
@ -759,12 +774,12 @@ return { a, b }
|
||||
exports[`SFC compile <script setup> imports should hoist and expose imports 1`] = `
|
||||
"import { ref } from 'vue'
|
||||
import 'foo/css'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { ref }
|
||||
}
|
||||
|
||||
@ -778,7 +793,7 @@ import { ref } from 'vue'
|
||||
import Foo, { bar } from './Foo.vue'
|
||||
import other from './util'
|
||||
import * as tree from './tree'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
@ -787,7 +802,7 @@ export default {
|
||||
const maybe = foo()
|
||||
let lett = 1
|
||||
function fn() {}
|
||||
|
||||
|
||||
return (_ctx, _cache) => {
|
||||
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
||||
_createVNode(Foo, null, {
|
||||
@ -811,11 +826,11 @@ exports[`SFC compile <script setup> inlineTemplate mode referencing scope compon
|
||||
import ChildComp from './Child.vue'
|
||||
import SomeOtherComp from './Other.vue'
|
||||
import vMyDir from './my-dir'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
|
||||
|
||||
return (_ctx, _cache) => {
|
||||
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
||||
_withDirectives(_createElementVNode(\\"div\\", null, null, 512 /* NEED_PATCH */), [
|
||||
@ -836,12 +851,12 @@ exports[`SFC compile <script setup> inlineTemplate mode should work 1`] = `
|
||||
const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"div\\", null, \\"static\\", -1 /* HOISTED */)
|
||||
|
||||
import { ref } from 'vue'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
const count = ref(0)
|
||||
|
||||
|
||||
return (_ctx, _cache) => {
|
||||
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
||||
_createElementVNode(\\"div\\", null, _toDisplayString(count.value), 1 /* TEXT */),
|
||||
@ -858,7 +873,7 @@ exports[`SFC compile <script setup> inlineTemplate mode ssr codegen 1`] = `
|
||||
import { ssrRenderAttrs as _ssrRenderAttrs, ssrInterpolate as _ssrInterpolate } from \\"vue/server-renderer\\"
|
||||
|
||||
import { ref } from 'vue'
|
||||
|
||||
|
||||
export default {
|
||||
__ssrInlineRender: true,
|
||||
setup(__props) {
|
||||
@ -868,7 +883,7 @@ _useCssVars(_ctx => ({
|
||||
}))
|
||||
|
||||
const count = ref(0)
|
||||
|
||||
|
||||
return (_ctx, _push, _parent, _attrs) => {
|
||||
const _cssVars = { style: {
|
||||
\\"xxxxxxxx-count\\": (count.value)
|
||||
@ -890,7 +905,7 @@ exports[`SFC compile <script setup> inlineTemplate mode template assignment expr
|
||||
"import { createElementVNode as _createElementVNode, isRef as _isRef, unref as _unref, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
|
||||
|
||||
import { ref } from 'vue'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
@ -898,7 +913,7 @@ export default {
|
||||
const maybe = foo()
|
||||
let lett = 1
|
||||
let v = ref(1)
|
||||
|
||||
|
||||
return (_ctx, _cache) => {
|
||||
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
||||
_createElementVNode(\\"div\\", {
|
||||
@ -947,7 +962,7 @@ exports[`SFC compile <script setup> inlineTemplate mode template destructure ass
|
||||
"import { createElementVNode as _createElementVNode, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
|
||||
|
||||
import { ref } from 'vue'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
@ -955,7 +970,7 @@ export default {
|
||||
const count = ref(0)
|
||||
const maybe = foo()
|
||||
let lett = 1
|
||||
|
||||
|
||||
return (_ctx, _cache) => {
|
||||
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
||||
_createElementVNode(\\"div\\", {
|
||||
@ -978,14 +993,14 @@ exports[`SFC compile <script setup> inlineTemplate mode template update expressi
|
||||
"import { createElementVNode as _createElementVNode, isRef as _isRef, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
|
||||
|
||||
import { ref } from 'vue'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
const count = ref(0)
|
||||
const maybe = foo()
|
||||
let lett = 1
|
||||
|
||||
|
||||
return (_ctx, _cache) => {
|
||||
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
||||
_createElementVNode(\\"div\\", {
|
||||
@ -1017,14 +1032,14 @@ exports[`SFC compile <script setup> inlineTemplate mode v-model codegen 1`] = `
|
||||
"import { vModelText as _vModelText, createElementVNode as _createElementVNode, withDirectives as _withDirectives, unref as _unref, isRef as _isRef, Fragment as _Fragment, openBlock as _openBlock, createElementBlock as _createElementBlock } from \\"vue\\"
|
||||
|
||||
import { ref } from 'vue'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
const count = ref(0)
|
||||
const maybe = foo()
|
||||
let lett = 1
|
||||
|
||||
|
||||
return (_ctx, _cache) => {
|
||||
return (_openBlock(), _createElementBlock(_Fragment, null, [
|
||||
_withDirectives(_createElementVNode(\\"input\\", {
|
||||
@ -1055,7 +1070,7 @@ exports[`SFC compile <script setup> inlineTemplate mode with defineExpose() 1`]
|
||||
|
||||
const count = ref(0)
|
||||
expose({ count })
|
||||
|
||||
|
||||
return () => {}
|
||||
}
|
||||
|
||||
@ -1069,7 +1084,7 @@ exports[`SFC compile <script setup> should expose top level declarations 1`] = `
|
||||
function cc() {}
|
||||
class dd {}
|
||||
import { x } from './x'
|
||||
|
||||
|
||||
export default {
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
@ -1078,7 +1093,7 @@ export default {
|
||||
const b = 2
|
||||
function c() {}
|
||||
class d {}
|
||||
|
||||
|
||||
return { aa, bb, cc, dd, a, b, c, d, xx, x }
|
||||
}
|
||||
|
||||
@ -1088,12 +1103,12 @@ return { aa, bb, cc, dd, a, b, c, d, xx, x }
|
||||
exports[`SFC compile <script setup> with TypeScript const Enum 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
const enum Foo { A = 123 }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { Foo }
|
||||
}
|
||||
|
||||
@ -1103,14 +1118,14 @@ return { Foo }
|
||||
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (exported interface) 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
export interface Emits { (e: 'foo' | 'bar'): void }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
emits: [\\"foo\\", \\"bar\\"],
|
||||
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
@ -1120,14 +1135,14 @@ return { emit }
|
||||
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (exported type alias) 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
export type Emits = { (e: 'foo' | 'bar'): void }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
emits: [\\"foo\\", \\"bar\\"],
|
||||
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
@ -1137,14 +1152,14 @@ return { emit }
|
||||
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (interface) 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
interface Emits { (e: 'foo' | 'bar'): void }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
emits: [\\"foo\\", \\"bar\\"],
|
||||
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
@ -1154,14 +1169,14 @@ return { emit }
|
||||
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (referenced exported function type) 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
export type Emits = (e: 'foo' | 'bar') => void
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
emits: [\\"foo\\", \\"bar\\"],
|
||||
setup(__props, { expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
@ -1171,14 +1186,14 @@ return { emit }
|
||||
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (referenced function type) 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
type Emits = (e: 'foo' | 'bar') => void
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
emits: [\\"foo\\", \\"bar\\"],
|
||||
setup(__props, { expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
@ -1188,14 +1203,14 @@ return { emit }
|
||||
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (type alias) 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
type Emits = { (e: 'foo' | 'bar'): void }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
emits: [\\"foo\\", \\"bar\\"],
|
||||
setup(__props, { expose, emit }: { emit: ({ (e: 'foo' | 'bar'): void }), expose: any, slots: any, attrs: any }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
@ -1210,8 +1225,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose, emit }: { emit: ({(e: 'foo' | 'bar'): void; (e: 'baz', id: number): void;}), expose: any, slots: any, attrs: any }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
@ -1226,8 +1241,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { emit }
|
||||
}
|
||||
|
||||
@ -1237,7 +1252,7 @@ return { emit }
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ exported interface 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
export interface Props { x?: number }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
@ -1245,8 +1260,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props: any, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
@ -1257,7 +1272,7 @@ exports[`SFC compile <script setup> with TypeScript defineProps w/ exported inte
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
|
||||
export interface Props { x?: number }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
@ -1265,8 +1280,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props: any, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
@ -1276,7 +1291,7 @@ return { }
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ exported type alias 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
export type Props = { x?: number }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
@ -1284,8 +1299,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props: any, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
@ -1295,7 +1310,7 @@ return { }
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ interface 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
interface Props { x?: number }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
@ -1303,8 +1318,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props: any, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
@ -1317,7 +1332,7 @@ interface Test {}
|
||||
|
||||
type Alias = number[]
|
||||
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
props: {
|
||||
string: { type: String, required: true },
|
||||
@ -1350,8 +1365,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props: any, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
@ -1361,7 +1376,7 @@ return { }
|
||||
exports[`SFC compile <script setup> with TypeScript defineProps w/ type alias 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
type Props = { x?: number }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
props: {
|
||||
x: { type: Number, required: false }
|
||||
@ -1369,8 +1384,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props: any, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
@ -1401,12 +1416,12 @@ exports[`SFC compile <script setup> with TypeScript hoist type declarations 1`]
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
export interface Foo {}
|
||||
type Bar = {}
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { }
|
||||
}
|
||||
|
||||
@ -1417,12 +1432,12 @@ exports[`SFC compile <script setup> with TypeScript import type 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
import type { Foo } from './main.ts'
|
||||
import { type Bar, Baz } from './main.ts'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { Baz }
|
||||
}
|
||||
|
||||
@ -1432,12 +1447,12 @@ return { Baz }
|
||||
exports[`SFC compile <script setup> with TypeScript runtime Enum 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
enum Foo { A = 123 }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { Foo }
|
||||
}
|
||||
|
||||
@ -1447,16 +1462,16 @@ return { Foo }
|
||||
exports[`SFC compile <script setup> with TypeScript runtime Enum in normal script 1`] = `
|
||||
"import { defineComponent as _defineComponent } from 'vue'
|
||||
enum Foo { A = 123 }
|
||||
|
||||
|
||||
export enum D { D = \\"D\\" }
|
||||
const enum C { C = \\"C\\" }
|
||||
enum B { B = \\"B\\" }
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
setup(__props, { expose }) {
|
||||
expose();
|
||||
|
||||
|
||||
|
||||
return { D, C, B, Foo }
|
||||
}
|
||||
|
||||
@ -1466,7 +1481,7 @@ return { D, C, B, Foo }
|
||||
exports[`SFC compile <script setup> with TypeScript withDefaults (dynamic) 1`] = `
|
||||
"import { mergeDefaults as _mergeDefaults, defineComponent as _defineComponent } from 'vue'
|
||||
import { defaults } from './foo'
|
||||
|
||||
|
||||
export default /*#__PURE__*/_defineComponent({
|
||||
props: _mergeDefaults({
|
||||
foo: { type: String, required: false },
|
||||
@ -1482,8 +1497,8 @@ const props = __props as {
|
||||
baz: boolean
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { props, defaults }
|
||||
}
|
||||
|
||||
@ -1505,8 +1520,8 @@ export default /*#__PURE__*/_defineComponent({
|
||||
|
||||
const props = __props as { foo: string, bar?: number, baz: boolean, qux(): number }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return { props }
|
||||
}
|
||||
|
||||
|
@ -168,6 +168,16 @@ defineExpose({ foo: 123 })
|
||||
expect(content).toMatch(/\bexpose\(\{ foo: 123 \}\)/)
|
||||
})
|
||||
|
||||
test('<script> after <script setup> the script content not end with `\\n`',() => {
|
||||
const { content } = compile(`
|
||||
<script setup>
|
||||
import { x } from './x'
|
||||
</script>
|
||||
<script>const n = 1</script>
|
||||
`)
|
||||
assertCode(content)
|
||||
})
|
||||
|
||||
describe('<script> and <script setup> co-usage', () => {
|
||||
test('script first', () => {
|
||||
const { content } = compile(`
|
||||
|
@ -943,6 +943,11 @@ export function compileScript(
|
||||
// declared before being used in the actual component definition
|
||||
if (scriptStartOffset! > startOffset) {
|
||||
s.move(scriptStartOffset!, scriptEndOffset!, 0)
|
||||
const content = s.slice(scriptStartOffset!, scriptEndOffset!)
|
||||
// when the script content not end with `\n` we add `\n` for the script content
|
||||
if(!/(\n *$)/.test(content)) {
|
||||
s.overwrite(scriptStartOffset!,scriptEndOffset!,`${content}\n`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user