c27363de3ea75fd165e5e34dcff3d5bee7b87961a47afafc1a9f8831fe8600b6e64602e5fe7873400898758da8db9534efc05f62624e7300e17496e3e55467 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # babel-plugin-transform-es2015-template-literals
  2. > Compile ES2015 template literals to ES5
  3. ## Example
  4. **In**
  5. ```javascript
  6. `foo${bar}`;
  7. ```
  8. **Out**
  9. ```javascript
  10. "foo" + bar;
  11. ```
  12. ## Installation
  13. ```sh
  14. npm install --save-dev babel-plugin-transform-es2015-template-literals
  15. ```
  16. ## Usage
  17. ### Via `.babelrc` (Recommended)
  18. **.babelrc**
  19. ```js
  20. // without options
  21. {
  22. "plugins": ["transform-es2015-template-literals"]
  23. }
  24. // with options
  25. {
  26. "plugins": [
  27. ["transform-es2015-template-literals", {
  28. "loose": true,
  29. "spec": true
  30. }]
  31. ]
  32. }
  33. ```
  34. ### Via CLI
  35. ```sh
  36. babel --plugins transform-es2015-template-literals script.js
  37. ```
  38. ### Via Node API
  39. ```javascript
  40. require("babel-core").transform("code", {
  41. plugins: ["transform-es2015-template-literals"]
  42. });
  43. ```
  44. ## Options
  45. ### `loose`
  46. In loose mode, tagged template literal objects aren't frozen.
  47. ### `spec`
  48. This option wraps all template literal expressions with `String`. See [babel/babel#1065](https://github.com/babel/babel/issues/1065) for more info.
  49. **In**
  50. ```javascript
  51. `foo${bar}`;
  52. ```
  53. **Out**
  54. ```javascript
  55. "foo" + String(bar);
  56. ```