mirror of https://github.com/vuejs/core.git
perf(compiler-sfc): remove magic-string trim on script
magic-string's trim method uses a regex check for aborting which turns out to be extremely expensive - it cna take up to 10% time in total SFC compilation! The usage here is purely aesthetic so simply removing it for a big perf gain is well worth it.
This commit is contained in:
parent
20732366b9
commit
e8e3ec6ca7
|
@ -14,7 +14,8 @@ return { a }
|
|||
`;
|
||||
|
||||
exports[`SFC analyze <script> bindings > auto name inference > do not overwrite manual name (call) 1`] = `
|
||||
"import { defineComponent } from 'vue'
|
||||
"
|
||||
import { defineComponent } from 'vue'
|
||||
const __default__ = defineComponent({
|
||||
name: 'Baz'
|
||||
})
|
||||
|
@ -30,7 +31,8 @@ return { a, defineComponent }
|
|||
`;
|
||||
|
||||
exports[`SFC analyze <script> bindings > auto name inference > do not overwrite manual name (object) 1`] = `
|
||||
"const __default__ = {
|
||||
"
|
||||
const __default__ = {
|
||||
name: 'Baz'
|
||||
}
|
||||
|
||||
|
@ -45,7 +47,8 @@ return { a }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > <script> and <script setup> co-usage > export call expression as default 1`] = `
|
||||
"function fn() {
|
||||
"
|
||||
function fn() {
|
||||
return \\"hello, world\\";
|
||||
}
|
||||
const __default__ = fn();
|
||||
|
@ -63,7 +66,8 @@ return { fn }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > <script> and <script setup> co-usage > keep original semi style 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
props: ['item'],
|
||||
emits: ['change'],
|
||||
setup(__props, { expose: __expose, emit: __emit }) {
|
||||
|
@ -535,7 +539,8 @@ return { get a() { return a }, set a(v) { a = v } }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > async/await detection > should ignore await inside functions 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
__expose();
|
||||
async function foo() { await bar }
|
||||
|
@ -546,7 +551,8 @@ return { foo }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > async/await detection > should ignore await inside functions 2`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
__expose();
|
||||
const foo = async () => { await bar }
|
||||
|
@ -557,7 +563,8 @@ return { foo }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > async/await detection > should ignore await inside functions 3`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
__expose();
|
||||
const obj = { async method() { await bar }}
|
||||
|
@ -568,7 +575,8 @@ return { obj }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > async/await detection > should ignore await inside functions 4`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
__expose();
|
||||
const cls = class Foo { async method() { await bar }}
|
||||
|
@ -618,7 +626,8 @@ return { a }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > binding analysis for destructure 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
__expose();
|
||||
|
||||
|
@ -838,7 +847,9 @@ return { msg, useCssVars, ref }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > imports > import dedupe between <script> and <script setup> 1`] = `
|
||||
"import { x } from './x'
|
||||
"
|
||||
|
||||
import { x } from './x'
|
||||
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
|
@ -902,7 +913,9 @@ return { ref }
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > imports > should support module string names syntax 1`] = `
|
||||
"import { \\"😏\\" as foo } from './foo'
|
||||
"
|
||||
|
||||
import { \\"😏\\" as foo } from './foo'
|
||||
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
|
@ -1189,7 +1202,8 @@ return (_ctx, _cache) => {
|
|||
`;
|
||||
|
||||
exports[`SFC compile <script setup> > inlineTemplate mode > with defineExpose() 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
|
||||
const count = ref(0)
|
||||
|
@ -1352,7 +1366,8 @@ return { a }
|
|||
`;
|
||||
|
||||
exports[`SFC genDefaultAs > <script> + <script setup> 1`] = `
|
||||
"const __default__ = {}
|
||||
"
|
||||
const __default__ = {}
|
||||
|
||||
const _sfc_ = /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose: __expose }) {
|
||||
|
@ -1367,7 +1382,8 @@ return { a }
|
|||
`;
|
||||
|
||||
exports[`SFC genDefaultAs > <script> + <script setup> 2`] = `
|
||||
"const __default__ = {}
|
||||
"
|
||||
const __default__ = {}
|
||||
|
||||
const _sfc_ = /*#__PURE__*/Object.assign(__default__, {
|
||||
setup(__props, { expose: __expose }) {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`defineEmits > basic usage 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
emits: ['foo', 'bar'],
|
||||
setup(__props, { expose: __expose, emit: __emit }) {
|
||||
__expose();
|
||||
|
|
|
@ -16,7 +16,8 @@ return { n, get x() { return x } }
|
|||
`;
|
||||
|
||||
exports[`defineExpose() 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
|
||||
__expose({ foo: 123 })
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`defineOptions() > basic usage 1`] = `
|
||||
"export default /*#__PURE__*/Object.assign({ name: 'FooApp' }, {
|
||||
"
|
||||
export default /*#__PURE__*/Object.assign({ name: 'FooApp' }, {
|
||||
setup(__props, { expose: __expose }) {
|
||||
__expose();
|
||||
|
||||
|
@ -14,7 +15,8 @@ return { }
|
|||
`;
|
||||
|
||||
exports[`defineOptions() > empty argument 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props, { expose: __expose }) {
|
||||
__expose();
|
||||
|
||||
|
|
|
@ -177,7 +177,8 @@ return () => {}
|
|||
`;
|
||||
|
||||
exports[`sfc reactive props destructure > defineProps/defineEmits in multi-variable declaration (full removal) 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
props: ['item'],
|
||||
emits: ['a'],
|
||||
setup(__props, { emit: __emit }) {
|
||||
|
@ -192,7 +193,8 @@ return () => {}
|
|||
`;
|
||||
|
||||
exports[`sfc reactive props destructure > multi-variable declaration 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
props: ['item'],
|
||||
setup(__props) {
|
||||
|
||||
|
@ -205,7 +207,8 @@ return () => {}
|
|||
`;
|
||||
|
||||
exports[`sfc reactive props destructure > multi-variable declaration fix #6757 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
props: ['item'],
|
||||
setup(__props) {
|
||||
|
||||
|
@ -218,7 +221,8 @@ return () => {}
|
|||
`;
|
||||
|
||||
exports[`sfc reactive props destructure > multi-variable declaration fix #7422 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
props: ['item'],
|
||||
setup(__props) {
|
||||
|
||||
|
@ -250,7 +254,8 @@ return (_ctx, _cache) => {
|
|||
`;
|
||||
|
||||
exports[`sfc reactive props destructure > nested scope 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
props: ['foo', 'bar'],
|
||||
setup(__props) {
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`sfc hoist static > should enable when only script setup 1`] = `
|
||||
"const foo = 'bar'
|
||||
"
|
||||
const foo = 'bar'
|
||||
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
@ -91,7 +92,8 @@ return () => {}
|
|||
`;
|
||||
|
||||
exports[`sfc hoist static > should not hoist a function or class 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
const fn = () => {}
|
||||
|
@ -105,7 +107,8 @@ return () => {}
|
|||
`;
|
||||
|
||||
exports[`sfc hoist static > should not hoist a object or array 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
const obj = { foo: 'bar' }
|
||||
|
@ -118,7 +121,8 @@ return () => {}
|
|||
`;
|
||||
|
||||
exports[`sfc hoist static > should not hoist a variable 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
let KEY1 = 'default value'
|
||||
|
@ -133,7 +137,8 @@ return () => {}
|
|||
`;
|
||||
|
||||
exports[`sfc hoist static > should not hoist when disabled 1`] = `
|
||||
"export default {
|
||||
"
|
||||
export default {
|
||||
setup(__props) {
|
||||
|
||||
const foo = 'bar'
|
||||
|
|
|
@ -986,8 +986,6 @@ export function compileScript(
|
|||
)
|
||||
}
|
||||
|
||||
ctx.s.trim()
|
||||
|
||||
return {
|
||||
...scriptSetup,
|
||||
bindings: ctx.bindingMetadata,
|
||||
|
|
Loading…
Reference in New Issue