babel 中的八进制数
Octal numbers in babel
我在玩babel-cli
。我安装了 ES2015 扩展并且运行良好。例如,以下代码段:
let square = x => x * x;
...转换为:
"use strict";
var square = function square(x) {
return x * x;
};
但是我在使用八进制数字时遇到了麻烦。例如:
let mode = 0777;
给我一个错误:
SyntaxError: index.js: Invalid number (1:11)
> 1 | let mode = 0777;
| ^
2 |
好像不喜欢0
开头的数字(八进制数)。我该如何解决这个问题?
事实上,这些数字并未出现在我的代码中,而是出现在其中一个依赖项中。
这是 babel 错误还是功能? workaround/solution是什么?
你做错了,它应该像 let mode = 0o777;
,注意 0 和 [=23] 之间的 o =]777
ES6 文档在这里:Binary and Octal Literals
// try this in chrome
document.write(0o777);
我在玩babel-cli
。我安装了 ES2015 扩展并且运行良好。例如,以下代码段:
let square = x => x * x;
...转换为:
"use strict";
var square = function square(x) {
return x * x;
};
但是我在使用八进制数字时遇到了麻烦。例如:
let mode = 0777;
给我一个错误:
SyntaxError: index.js: Invalid number (1:11)
> 1 | let mode = 0777;
| ^
2 |
好像不喜欢0
开头的数字(八进制数)。我该如何解决这个问题?
事实上,这些数字并未出现在我的代码中,而是出现在其中一个依赖项中。
这是 babel 错误还是功能? workaround/solution是什么?
你做错了,它应该像 let mode = 0o777;
,注意 0 和 [=23] 之间的 o =]777
ES6 文档在这里:Binary and Octal Literals
// try this in chrome
document.write(0o777);