- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Babel 是如何实现尾递归的?
这是怎么做到的transpiled es5 code工作?
最佳答案
我想我会发布一个详细的解释,让那些从谷歌登陆这里的人希望能够更快地理解。
请注意,以下解释是我从代码中可以看出的(没有与 Babel 的作者或其他代码专家进行咨询),所以不知道我推导出的意思是否是@sebmck 或其他为这一转变做出贡献的人。
"use strict"; // ES2015/ES6 modules are assumed to be in strict mode.
function factorial(_x2) {
// This variable is the list of arguments to factorial.
// Since factorial may be called again from within this function
// (but must be called indirectly to prevent call stack growth),
// a custom arguments-like variable must be maintained.
var _arguments = arguments;
// _again equals true when the original factorial function should be called
// once more.
var _again = true;
// This line creates a labeled while loop, use to allow continuing this
// specific loop, without the requirement of having no nested while loops
// Nested while loops would cause a "continue" statement within them to
// execute them, not this loop.
_function: while (_again) {
// The variable used in the original factorial function was called "n",
// this method allows Babel to not rename it, but simply assign the
// possibly modified first argument of the factorial function to it.
var n = _x2;
// Temporal dead zone (TDZ) mechanic
acc = undefined;
// The "use strict" directive from the original function
"use strict";
// Beginning of user code, this is always inserted to ensure that if
// this is the final run, the while loop will not run again.
_again = false;
// This is Babel's default argument handling. The steps, in order, are:
// 1. Make sure that there will not be an out-of-bounds access for the
// undefined check.
// 2. Check if the second argument to the current iteration is undefined,
// if yes: the default value is `1`, if no, use the value of the first argument.
var acc = _arguments.length <= 1 || _arguments[1] === undefined ? 1 : _arguments[1];
// Input code - no modifications.
if (n <= 1) return acc;
// The following three lines are the call to factorial() within factorial
// in the input code. The first line assigns the new arguments, as well
// as updating the _x2 variable to it's new value. The second line
// overrides the assignment in the beginning of the loop.
// The third line brings the loop back to the beginning.
_arguments = [_x2 = n - 1, n * acc];
_again = true;
continue _function;
}
}
关于javascript - BabelJS 是如何实现尾递归的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30368916/
我正在尝试使用 节点检查器 调试 节点JS 使用 运行的应用程序通天塔节点 . babel-node index.js --debug 节点检查器有效,但它在转译的 es5 而不是 es6 中显示源映
我看到我的 eslint 规则应用于 VSCode,但它们在 Babel 中不起作用。我认为我需要清除缓存,但我不知道该怎么做。 你能告诉我怎么做吗? 规则 "@typescript-eslint/c
我在项目的根目录下有一个.babelrc文件: { "presets": ["es2015"], "ignore": [ "src" ] } 当我使用babel src --out
我有一个来自我的 js/index.js 的服务人员: import '../scss/app.scss'; // Detect if service workers enabled if ('ser
我正在尝试为babel编写一个插件,并且需要正在解析的当前文件的文件名。我知道代码行已传入,但是我还没有找到对文件名的引用。有帮助吗? 例如给出此代码我该怎么办 export default func
我找到了much upvoted answer对于一个问题,代码如下: var condition = true; return ( ); 为什么需要...?如果我省略它,babel 就会向我提
我正在构建一个插件,该插件通过调用enterFunction()在每个现有函数调用的前面插入path.insertBefore。所以我的代码是从: myFunction(); 至: enterFunc
我已经安装了Babel,发现为了编译JSX,需要更改.babelrc文件吗?文件在哪里?我正在查看babel-preset,babel,babel-jsx文件夹等,但是找不到它吗?应该手动创建吗? 最
起初,如果 eslint,atom 会抛出这个错误。没有在 React 项目中保存为依赖项,它会以红色通知的形式弹出。 现在我在一个目录中工作 不是 一个 git repo,每当我尝试输入时,它都会不
我不明白黑白 babel 的区别 exclude对比 ignore即使在阅读了他们的文档后也可以选择。 我的理解是exclude不如 ignore 激进.和 exclude使当前配置对象处于非事件状态
我正在尝试获取 nyc ava和 babel到所有地方都很好。我遇到了 async/await 分支显示为未覆盖的问题,所以这是有效的,我在集成 babel-plugin-istanbul 时遇到问题
我正在安装 babel core 6.26.0 per this documentation ,一切顺利,除了出现以下错误: npm WARN optional Skipping failed opt
我已经搜索了 Babel 的文档,但似乎找不到答案,所以我转向了光荣的社区。 使用这样的目录结构: src/ folder1/ file1.js file2.j
给定以下示例目录结构: srcDir/file1.js srcDir/subDir1/file2.js srcDir/subDir2/file3.js 我想用 babel-cli 处理这些文件以便输出
我无法使用@compulated。如果我运行下面的代码,我会收到错误: Uncaught TypeError: An element descriptor's .kind property must
Babel 是如何实现尾递归的? 这是怎么做到的transpiled es5 code工作? 最佳答案 我想我会发布一个详细的解释,让那些从谷歌登陆这里的人希望能够更快地理解。 请注意,以下解释是我从
这个问题在这里已经有了答案: Extending built-in natives in ES6 with Babel (3 个答案) 关闭 7 年前。 我从 MDN 得到了这个示例代码(稍微修改以
问题是如何在调用super方法之前从构造函数内访问类静态属性? class A { constructor(input) { console.log('A', typeof n
这是配置文件: { "presets": [ "@babel/preset-env" ], "plugins": [ "@babel/plugi
Babel 正在用 void 0 替换 this 我该如何防止这种行为? 我有这个代码: ((parent)=>{ parent.something = {} })(this) 使用 babel
我是一名优秀的程序员,十分优秀!