Spread before condition in ternery operator spreads result

I came accross this in the React Starter Kit recently

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Move modules that occur in multiple entry chunks to a new entry chunk (the commons chunk).
// http://webpack.github.io/docs/list-of-plugins.html#commonschunkplugin
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: module => /node_modules/.test(module.resource),
}),
...isDebug ? [] : [
// Assign the module and chunk ids by occurrence count
// Consistent ordering of modules required if using any hashing ([hash] or [chunkhash])
// https://webpack.github.io/docs/list-of-plugins.html#occurrenceorderplugin
new webpack.optimize.OccurrenceOrderPlugin(true),
// Search for equal or similar files and deduplicate them in the output
// https://webpack.github.io/docs/list-of-plugins.html#dedupeplugin
new webpack.optimize.DedupePlugin(),

Breaking it down

1
2
3
4
5
6
[
...true
? 'foo'
: 'bar'
]
// ['f', 'o', 'o']

This is a bit wierd considering

1
2
+true ? '10' : '20'
// '10'

According to this logic I would have expected the number 10 not the string

1
2
+(true ? '10' : '20')
// 10

Adding parentheses around the numeric example results in a number of course

I’m guessing this is a case of javascript being cleaver, it can’t spread a boolean (the ternery condition) so it evaluates the expression first. But in the unary plus boolean example it can convert the boolean to a Numeric value and so evalutes that first and then the tenery. Maybe I’ll go read the spec a little later to find out what the deal is.