babeljs - 在 babel-standalone 中禁用 "use strict"

标签 babeljs

Using Babel-Standalone ,我正在尝试禁用 use strict ,以便我可以使用已弃用的 with 语句 the es2015 preset reference

var code = "with (p) {  // do something }";
var output = Babel.transform(code, { presets: [['es2015', {"loose": true}]] }).code;

这给了我这个错误:

babel.js:17955 Uncaught SyntaxError: unknown: 'with' in strict mode (1:5)

如何使用 Babel Standalone 禁用严格模式?

最佳答案

答案是 parserOpts 属性,它对应于 options.jsBabylon

var output = Babel.transform(code, 
{ 
   presets: ['es2015'], 
   parserOpts: { strictMode: false } 
});

关于babeljs - 在 babel-standalone 中禁用 "use strict",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41944982/

相关文章:

ecmascript-6 - babel 如何实现 Set/Map polyfills

javascript - api.cache(true) 在 Expo 的 babel.config.js 中做了什么?

javascript - Webpack - 没有输出文件,没有错误报告

node.js - 如何在 webpack 中同时使用 ES6 加载器和 brfs 转换?

javascript - 可选链接在 create-react-app 中不起作用

javascript - 有没有办法在 React.render() 函数中渲染多个 React 组件?

javascript - 找不到模块 : Error: Can't resolve 'font-awesome'

javascript - 巴别塔 7 & SystemJS 2 : "Unable to resolve bare specifier core-js/modules/web.dom.iterable"

javascript - 是否可以在 babel 7 上解构导入?

javascript - 如何使用webpack/babel预解析JS模板字符串?