Skip to content

Commit e2141a0

Browse files
committed
move named exports check to generated code (fix vuejs#599)
1 parent 5eec6ae commit e2141a0

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lib/component-normalizer.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
module.exports = function normalizeComponent (
2-
scriptExports,
2+
rawScriptExports,
33
compiledTemplate,
44
scopeId,
55
cssModules
66
) {
7-
scriptExports = scriptExports || {}
7+
var esModule
8+
var scriptExports = rawScriptExports = rawScriptExports || {}
89

910
// ES6 modules interop
10-
var type = typeof scriptExports.default
11+
var type = typeof rawScriptExports.default
1112
if (type === 'object' || type === 'function') {
12-
// check named exports
13-
if (process.env.NODE_ENV !== 'production') {
14-
if (Object.keys(scriptExports).some(function (key) {
15-
return key !== 'default' && key !== '__esModule'
16-
})) {
17-
console.error('named exports are not supported in *.vue files.')
18-
}
19-
}
20-
scriptExports = scriptExports.default
13+
esModule = rawScriptExports
14+
scriptExports = rawScriptExports.default
2115
}
2216

2317
// Vue.extend constructor export interop
@@ -46,6 +40,7 @@ module.exports = function normalizeComponent (
4640
}
4741

4842
return {
43+
esModule: esModule,
4944
exports: scriptExports,
5045
options: options
5146
}

lib/loader.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,13 @@ module.exports = function (content) {
299299
if (!isProduction) {
300300
// add filename in dev
301301
output += 'Component.options.__file = ' + JSON.stringify(filePath) + '\n'
302+
// check named exports
303+
output +=
304+
'if (Component.esModule && Object.keys(Component.esModule).some(function (key) {' +
305+
'return key !== "default" && key !== "__esModule"' +
306+
'})) {' +
307+
'console.error("named exports are not supported in *.vue files.")' +
308+
'}\n'
302309
// check functional components used with templates
303310
if (template) {
304311
output +=

0 commit comments

Comments
 (0)