Browse Source

build: introduce feature flags, hide new slot syntax behind flag

dev
Evan You 6 years ago
parent
commit
7fb6fdd168
  1. 9
      scripts/config.js
  2. 3
      scripts/feature-flags.js
  3. 10
      src/compiler/parser/index.js
  4. 2
      src/core/vdom/helpers/normalize-scoped-slots.js
  5. 8
      test/unit/features/component/component-scoped-slot.spec.js
  6. 4
      test/unit/karma.base.config.js

9
scripts/config.js

@ -7,6 +7,7 @@ const node = require('rollup-plugin-node-resolve')
const flow = require('rollup-plugin-flow-no-whitespace')
const version = process.env.VERSION || require('../package.json').version
const weexVersion = process.env.WEEX_VERSION || require('../packages/weex-vue-framework/package.json').version
const featureFlags = require('./feature-flags')
const banner =
'/*!\n' +
@ -241,9 +242,13 @@ function genConfig (name) {
}
if (opts.env) {
config.plugins.push(replace({
const vars = {
'process.env.NODE_ENV': JSON.stringify(opts.env)
}))
}
Object.keys(featureFlags).forEach(key => {
vars[`process.env.${key}`] = featureFlags[key]
})
config.plugins.push(replace(vars))
}
if (opts.transpile !== false) {

3
scripts/feature-flags.js

@ -0,0 +1,3 @@
module.exports = {
NEW_SLOT_SYNTAX: false
}

10
src/compiler/parser/index.js

@ -568,11 +568,12 @@ function processSlotContent (el) {
}
el.slotScope = (
slotScope ||
getAndRemoveAttr(el, 'slot-scope') ||
getAndRemoveAttr(el, 'slot-scope')
)
if (process.env.NEW_SLOT_SYNTAX) {
// new in 2.6: slot-props and its shorthand works the same as slot-scope
// when used on <template> containers
getAndRemoveAttr(el, 'slot-props')
)
el.slotScope = el.slotScope || getAndRemoveAttr(el, 'slot-props')
// 2.6 shorthand syntax
const shorthand = getAndRemoveAttrByRegex(el, scopedSlotShorthandRE)
if (shorthand) {
@ -585,6 +586,7 @@ function processSlotContent (el) {
el.slotTarget = getScopedSlotShorthandName(shorthand)
el.slotScope = shorthand.value
}
}
} else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
/* istanbul ignore if */
if (process.env.NODE_ENV !== 'production' && el.attrsMap['v-for']) {
@ -597,7 +599,7 @@ function processSlotContent (el) {
)
}
el.slotScope = slotScope
} else {
} else if (process.env.NEW_SLOT_SYNTAX) {
// 2.6: slot-props on component, denotes default slot
slotScope = getAndRemoveAttr(el, 'slot-props')
const shorthand = getAndRemoveAttrByRegex(el, scopedSlotShorthandRE)

2
src/core/vdom/helpers/normalize-scoped-slots.js

@ -32,7 +32,7 @@ export function normalizeScopedSlots (
function normalizeScopedSlot(fn: Function): Function {
return scope => {
const res = fn(scope)
return res && typeof res === 'object'
return res && typeof res === 'object' && !Array.isArray(res)
? [res] // single vnode
: normalizeChildren(res)
}

8
test/unit/features/component/component-scoped-slot.spec.js

@ -632,7 +632,8 @@ describe('Component scoped slot', () => {
}).then(done)
})
// new in 2.6
// 2.6 new slot syntax
if (process.env.NEW_SLOT_SYNTAX) {
describe('slot-props syntax', () => {
const Foo = {
render(h) {
@ -646,13 +647,13 @@ describe('Component scoped slot', () => {
const Bar = {
render(h) {
return this.$scopedSlots.default && this.$scopedSlots.default('from bar')[0]
return this.$scopedSlots.default && this.$scopedSlots.default('from bar')
}
}
const Baz = {
render(h) {
return this.$scopedSlots.default && this.$scopedSlots.default('from baz')[0]
return this.$scopedSlots.default && this.$scopedSlots.default('from baz')
}
}
@ -792,4 +793,5 @@ describe('Component scoped slot', () => {
expect(vm.$el.innerHTML.replace(/\s+/g, ' ')).toMatch(`from foo one from foo two`)
})
})
}
})

4
test/unit/karma.base.config.js

@ -1,4 +1,5 @@
const alias = require('../../scripts/alias')
const featureFlags = require('../../scripts/feature-flags')
const webpack = require('webpack')
const webpackConfig = {
@ -20,7 +21,8 @@ const webpackConfig = {
__WEEX__: false,
'process.env': {
TRANSITION_DURATION: process.env.CI ? 100 : 50,
TRANSITION_BUFFER: 10
TRANSITION_BUFFER: 10,
...featureFlags
}
})
],

Loading…
Cancel
Save