refactor: rename optimizeBindings -> optimizeImports

This commit is contained in:
Evan You 2020-07-10 20:43:52 -04:00
parent 5f271515cf
commit b51b79f5c4
5 changed files with 14 additions and 14 deletions

View File

@ -171,7 +171,7 @@ export function render(_ctx, _cache) {
}" }"
`; `;
exports[`compiler: codegen module mode preamble w/ optimizeBindings: true 1`] = ` exports[`compiler: codegen module mode preamble w/ optimizeImports: true 1`] = `
"import { createVNode, resolveDirective } from \\"vue\\" "import { createVNode, resolveDirective } from \\"vue\\"
// Binding optimization for webpack code-split // Binding optimization for webpack code-split

View File

@ -68,11 +68,11 @@ describe('compiler: codegen', () => {
expect(code).toMatchSnapshot() expect(code).toMatchSnapshot()
}) })
test('module mode preamble w/ optimizeBindings: true', () => { test('module mode preamble w/ optimizeImports: true', () => {
const root = createRoot({ const root = createRoot({
helpers: [CREATE_VNODE, RESOLVE_DIRECTIVE] helpers: [CREATE_VNODE, RESOLVE_DIRECTIVE]
}) })
const { code } = generate(root, { mode: 'module', optimizeBindings: true }) const { code } = generate(root, { mode: 'module', optimizeImports: true })
expect(code).toMatch( expect(code).toMatch(
`import { ${helperNameMap[CREATE_VNODE]}, ${ `import { ${helperNameMap[CREATE_VNODE]}, ${
helperNameMap[RESOLVE_DIRECTIVE] helperNameMap[RESOLVE_DIRECTIVE]

View File

@ -88,7 +88,7 @@ function createCodegenContext(
sourceMap = false, sourceMap = false,
filename = `template.vue.html`, filename = `template.vue.html`,
scopeId = null, scopeId = null,
optimizeBindings = false, optimizeImports = false,
runtimeGlobalName = `Vue`, runtimeGlobalName = `Vue`,
runtimeModuleName = `vue`, runtimeModuleName = `vue`,
ssr = false ssr = false
@ -100,7 +100,7 @@ function createCodegenContext(
sourceMap, sourceMap,
filename, filename,
scopeId, scopeId,
optimizeBindings, optimizeImports,
runtimeGlobalName, runtimeGlobalName,
runtimeModuleName, runtimeModuleName,
ssr, ssr,
@ -355,7 +355,7 @@ function genModulePreamble(
helper, helper,
newline, newline,
scopeId, scopeId,
optimizeBindings, optimizeImports,
runtimeModuleName runtimeModuleName
} = context } = context
@ -368,7 +368,7 @@ function genModulePreamble(
// generate import statements for helpers // generate import statements for helpers
if (ast.helpers.length) { if (ast.helpers.length) {
if (optimizeBindings) { if (optimizeImports) {
// when bundled with webpack with code-split, calling an import binding // when bundled with webpack with code-split, calling an import binding
// as a function leads to it being wrapped with `Object(a.b)` or `(0,a.b)`, // as a function leads to it being wrapped with `Object(a.b)` or `(0,a.b)`,
// incurring both payload size increase and potential perf overhead. // incurring both payload size increase and potential perf overhead.

View File

@ -155,7 +155,7 @@ export interface CodegenOptions {
* (only used for webpack code-split) * (only used for webpack code-split)
* @default false * @default false
*/ */
optimizeBindings?: boolean optimizeImports?: boolean
/** /**
* Customize where to import runtime helpers from. * Customize where to import runtime helpers from.
* @default 'vue' * @default 'vue'

View File

@ -6,7 +6,7 @@ export const ssrMode = ref(false)
export const compilerOptions: CompilerOptions = reactive({ export const compilerOptions: CompilerOptions = reactive({
mode: 'module', mode: 'module',
prefixIdentifiers: false, prefixIdentifiers: false,
optimizeBindings: false, optimizeImports: false,
hoistStatic: false, hoistStatic: false,
cacheHandlers: false, cacheHandlers: false,
scopeId: null scopeId: null
@ -144,18 +144,18 @@ const App = {
h('label', { for: 'scope-id' }, 'scopeId') h('label', { for: 'scope-id' }, 'scopeId')
]), ]),
// toggle optimizeBindings // toggle optimizeImports
h('li', [ h('li', [
h('input', { h('input', {
type: 'checkbox', type: 'checkbox',
id: 'optimize-bindings', id: 'optimize-imports',
disabled: !isModule || isSSR, disabled: !isModule || isSSR,
checked: isModule && !isSSR && compilerOptions.optimizeBindings, checked: isModule && !isSSR && compilerOptions.optimizeImports,
onChange(e: Event) { onChange(e: Event) {
compilerOptions.optimizeBindings = (e.target as HTMLInputElement).checked compilerOptions.optimizeImports = (e.target as HTMLInputElement).checked
} }
}), }),
h('label', { for: 'optimize-bindings' }, 'optimizeBindings') h('label', { for: 'optimize-imports' }, 'optimizeImports')
]) ])
]) ])
]) ])