testdouble / theredoc

Makes your multi-line JavaScript strings look good
80 stars 3 forks source link

Babel plugin? #1

Open developit opened 6 years ago

developit commented 6 years ago

It'd be awesome to have this with no runtime cost. Could it be done as a babel plugin?

searls commented 6 years ago

It's a pretty simple function, so I would hope it could! I don't use babel or know how to make plugins for it, but I'd hope someone would consider it!

Unsure if should keep open here.

elmigranto commented 6 years ago

There is a similar thing implemented by dedent called "babel-macro", but I'm not sure if it needs to be a part of theredoc or a separate thing.

https://www.npmjs.com/package/dedent https://github.com/dmnd/dedent/blob/master/macro.js

olsonpm commented 6 years ago

I hadn't heard of babel-macros before, it's a pretty great idea. All you need to do is:

  1. npm i babel-plugin-macros dedent

  2. Add macros to your list of babel plugins (wherever your babel config is)

  3. Use dedent e.g.

import dedent from 'dedent/macro'

logIndentedString()

function logIndentedString() {
  console.log(dedent(`
    This string
    is properly indented
      at compile time
  `))
}
reggi commented 6 years ago

This is failing on my jenkins build no node 4 support :(

node_modules/theredoc/index.js:1
(function (exports, require, module, __filename, __dirname) { module.exports = function theredoc (strings, ...values) {
                                                                                                           ^^^

SyntaxError: Unexpected token ...
    at exports.runInThisContext (vm.js:53:16)
searls commented 6 years ago

theredoc is failing or attempting to write a Babel macro is failing?

Part of why I waited to publish theredoc until now was that Node 4 was EOL'd on 4/30/18 and I finally felt comfortable dropping support from new releases of our open source.

On May 7, 2018, at 3:49 PM, Thomas Reggi notifications@github.com wrote:

This is failing on my jenkins build no node 4 support :(

node_modules/theredoc/index.js:1 (function (exports, require, module, filename, dirname) { module.exports = function theredoc (strings, ...values) { ^^^

SyntaxError: Unexpected token ... at exports.runInThisContext (vm.js:53:16)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.