ie10中的不可变记录getIn失败

时间:2016-06-07 07:08:12

标签: internet-explorer-10 babeljs immutable.js

这是不可变的记录类定义

import Immutable, {Record} from 'immutable';

const FEATURE_DEFAULTS = {
  name: null,
};

export class Feature extends Record(FEATURE_DEFAULTS) { 
}

实例以这种方式初始化:

const featureName = 'a value';
const b = new Feature({ name: featureName });

console.log(b.getIn(['name']));

在大多数现代浏览器(chrome,safari等)中,它都有效。它按预期打印出name字段中的值。

但是在ie10中,b.getIn(['name'])会抛出此异常:Unable to get property 'hasOwnProperty' of undefined or null reference

enter image description here

有关我的项目的更多信息,它使用这些依赖项

"immutable": "^3.8.1",
"react": "^15.1.0",
"react-chartist": "^0.10.1",
"react-dom": "^15.1.0",
"react-intl": "2.1.2",
"react-redux": "^4.4.5",
"react-router": "^2.4.1",
"redux": "^3.5.2",
"redux-thunk": "^2.1.0",
"reselect": "^2.5.1",

我也在使用babel翻译es6语法

"babel-core": "^6.9.1",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.9.0",
"babel-runtime": "^6.9.2",

我该如何解决这个问题?

编辑: 我认为例外是从这里抛出的:
https://github.com/facebook/immutable-js/blob/38019326a8d006a45ef48d9c4644e23ea476d298/src/Record.js#L55

1 个答案:

答案 0 :(得分:1)

我找到了babel的bug追踪器https://phabricator.babeljs.io/T3041

的解决方案

基本上步骤是:

  • npm install babel-plugin-transform-class-properties

  • npm install babel-plugin-transform-es2015-classe

  • 将这些插件添加到.babelrc

      "plugins": [
           "transform-class-properties",
           ['transform-es2015-classes', {loose: true}]
         ]