Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(compiler-sfc): ignore empty blocks #3520

Merged
merged 1 commit into from
Jul 19, 2021

Conversation

cexbrayat
Copy link
Member

The current implementation ignores <script/> and <styles/> but not empty blocks like <script> \n\t</script>.
This results in unnecessary code generated for a component when these blocks are actually empty.

This commit filters such nodes in the SFC compiler, resulting in less code generated.

For example, this component:

<template>
  <h1>{{ msg }}</h1>
</template>

<script setup>

</script>

<style scoped>
  
</style>

currently produces:

/* Analyzed bindings: {} */
import { toDisplayString as _toDisplayString, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from "vue"
const _withId = /*#__PURE__*/_withScopeId("data-v-f13b4d11")


const __sfc__ = {
  expose: [],
  setup(__props) {



return /*#__PURE__*/_withId((_ctx, _cache) => {
  return (_openBlock(), _createBlock("h1", null, _toDisplayString(_ctx.msg), 1 /* TEXT */))
})
}

}
__sfc__.__scopeId = "data-v-f13b4d11"
__sfc__.__file = "App.vue"
export default __sfc__

(see https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHRlbXBsYXRlPlxuICA8aDE+e3sgbXNnIH19PC9oMT5cbjwvdGVtcGxhdGU+XG5cbjxzY3JpcHQgc2V0dXA+XG5cbjwvc2NyaXB0PlxuXG48c3R5bGUgc2NvcGVkPlxuXG48L3N0eWxlPiJ9)

With this commit, it produces:

const __sfc__ = {}
import { toDisplayString as _toDisplayString, openBlock as _openBlock, createBlock as _createBlock } from "vue"
function render(_ctx, _cache) {
  return (_openBlock(), _createBlock("h1", null, _toDisplayString(_ctx.msg), 1 /* TEXT */))
}
__sfc__.render = render
__sfc__.__file = "App.vue"
export default __sfc__

The current implementation ignores `<script/>` and `<styles/>` but not empty blocks like `<script>  \n\t</script>`.
This results in unnecessary code generated for a component when these blocks are actually empty.

This commit filters such nodes int he SFC compiler, resulting in less code generated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants