compiler-errors - 我如何/在哪里告诉编译器使用 ecmascript 6

标签 compiler-errors ecmascript-6 google-tag-manager json-ld google-rich-snippets

我想要完成的事情:

为什么:

  • 创建 Rich CardSERP 中展示

问题:

尝试创建 User-Defined Variable 时以及 Tag 使用的脚本本身。使用 Preview and Debug 时GTM的特点。我收到以下错误:

this language feature is only supported for ECMASCRIPT6 mode or better: let declaration. Use --language_in=ECMASCRIPT6 or ECMASCRIPT6_STRICT to enable ES6 features.

我明白...或者至少我认为我明白我需要告诉编译器

Use --language_in=ECMASCRIPT6 or ECMASCRIPT6_STRICT

但是我该如何实现呢?

<script>
(function(){
// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name default.js
// @language_in=ECMASCRIPT6_STRICT;
// @language_out=ES5_STRICT;
 // ==/ClosureCompiler==

 "use strict";
  let data = {
  "@context": "http://schema.org",
  "@type": "MovingCompany",
  "name": "WDA Movers",
  "logo" : {
    "@type" : "ImageObject",
    "url" : "http://wda-moving.online/images/logo.jpg",
    "height" : 435,
    "width" : 361      
  },
  "address": {
    "@type": "PostalAddress",
    "addressLocality": "Eugene",
    "addressRegion": "OR",
    "postalCode": "97404",
    "streetAddress": "411 Heywood Avenue"
  },
  "openingHours": "Mo-Su 7:00-23:30",
  "priceRange": "$$$",
  "telephone": "(541) 255-9876",
  "url": "http://wda-moving.online",
  "sameAs" : [
    "https://www.facebook.com/wda.movers/",
    "https://plus.google.com/+WDAMoversEugene/about?gmbpt=true&hl=en"
  ],
  "aggregateRating": {
    "@type": "AggregateRating",
    "ratingValue": {{YELP_rating}},
    "reviewCount": {{YELP_review_count}},
    "bestRating": "5",
    "worstRating": "1"
  },
  "review": {
"@type" : "Review",
"author" : {{YELP_reviews_user_name}},
"reviewBody" : {{YELP_reviews_excerpt}},
"reviewRating" : {
    "@type": "Rating",
    "ratingValue": {{YELP_reviews_rating}}
    }
   }
 }
 let richCard = document.createElement('script');
 richCard.type = "application/ld+json";
 richCard.innerHTML = JSON.stringify(data);
 document.getElementsByTagName('head')[0].appendChild(richCard);
 })(document);
 </script>

如您所见,我已尝试将以下内容添加到上面的脚本中:

// ==ClosureCompiler==
// @compilation_level SIMPLE_OPTIMIZATIONS
// @output_file_name default.js
// @language_in=ECMASCRIPT6_STRICT;
// @language_out=ES5_STRICT;
// ==/ClosureCompiler==

"use strict";

这没有用...任何人都可以帮助我吗?

最佳答案

如果你看一下 asset-pipeline plugin ,您将找到以下 build.gradle 示例:

assets {
    minifyJs = true
    minifyCss = true
    enableSourceMaps = true
    configOptions = [:]

    minifyOptions = [
        languageMode: 'ES5',
        targetLanguage: 'ES5', //Can go from ES6 to ES5 for those bleeding edgers
        optimizationLevel: 'SIMPLE',
        angularPass: true // Can use @ngInject annotation for Angular Apps
    ]
    // ... snip ...
}

当我将 minifyOptions 中的 languageMode 设置为 'ES6' 时,错误消失并且在部署时提供正确的 JavaScript。当然,您也可以将 assets.minifyJs 设置为 false 以获得相同的效果。

关于compiler-errors - 我如何/在哪里告诉编译器使用 ecmascript 6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38961315/

相关文章:

c++ - sstream 重新声明公共(public)访问编译器错误

javascript - ES6 - 如何将 JSON 语法与模板文字保持一致?

javascript - 如何在 V8 中优化访问时间的小型对象引用数组?

javascript - 使用 Google 跟踪代码管理器自定义维度

c++ - 如何创建自定义 C++ 类以与蓝图一起使用

ios - objective c 隐式转换丢失整数精度 'NSUInteger'

java - “找不到符号”或“无法解析符号”错误是什么意思?

javascript - RxJS 将数组与另一个可观察量映射并返回数组

javascript - 使用谷歌标签管理器将综合浏览量发送到虚拟网址到谷歌分析

asp.net-mvc - Google Analytics-Universal Analytics代码可跟踪两种环境