const
类似于let
,it is a LexicalDeclaration(VariableStatement, Declaration),用于在挡路中定义标识符.
您正试图将其与default
关键字(which expects a HoistableDeclaration, ClassDeclaration or AssignmentExpression)混合在一起.
因此它是SyntaxError.
如果你想要const
个东西,你需要提供标识符,而不是使用default
.
export
本身接受其右边的VariableStatement或Declaration.
以下是export default Tab;
英镑的罚款.
Tab
变成了AssignmentExpression,因为它被命名为default
export default Tab = connect( mapState, mapDispatch )( Tabs );
元就可以了
这里Tab = connect( mapState, mapDispatch )( Tabs );
是AssignmentExpression.
Update:.想象问题的另一种方式
如果您试图从概念上理解这一点,而上面的规范推理无济于事,那么可以将其视为"if 100 was a legal identifier and not a reserved token, what would be a different way to write 101 and 102 ?"
在这种情况下,扩展的编写方式应该是
// pseudocode, this thought experiment is not valid JS
export default Foo;
// would be like
export const default = Foo;
export default const Foo = 1;
// would be like
export const default const Foo = 1;
// so would the following line make sense?
const bar const Foo = 1;
有一个有效的论点是,扩展should应该是这样的
// pseudocode, this thought experiment is not valid JS
export default const Foo = 1;
// would be like
const Foo = 1;
export const default = Foo;
然而,每Sergey's comment次,这将变得模棱两可,因此,显式地编写此模式更有意义.