将 ES2015 模板字符串编译为 ES5
输入
`foo${bar}`;
输出
"foo" + bar;
npm install --save-dev babel-plugin-transform-es2015-template-literals
.babelrc
未包含选项:
{
"plugins": ["transform-es2015-template-literals"]
}
包含选项:
{
"plugins": [
["transform-es2015-template-literals", {
"loose": true,
"spec": true
}]
]
}
babel --plugins transform-es2015-template-literals script.js
require("babel-core").transform("code", {
plugins: ["transform-es2015-template-literals"]
});
boolean
,默认为 false
。
在松散(loose)模式下,被标记的模板字符串对象不会被冻结。
boolean
,默认为 false
。
该选项用 String
包装所有模板字符串的表达式。请查阅 babel/babel#1065 了解更多。
输入
`foo${bar}`;
输出
"foo" + String(bar);