Using Babel-Standalone,我正在尝试停用use strict
,以便每个the es2015 preset reference使用弃用的with
语句。
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禁用严格模式?
答案 0 :(得分:3)
答案是parserOpts
属性,对应options.js中的Babylon
var output = Babel.transform(code,
{
presets: ['es2015'],
parserOpts: { strictMode: false }
});
答案 1 :(得分:1)
默认情况下,Babel将文件解析为ES6模块。你需要告诉它不要那样做,比如
<div ng-app="myApp" ng-controller="myCtrl">
<input ng-model="name">
<h1>{{name}}</h1><br>
<p ng-bind="name"></p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.name = "John Doe";
});
</script>