Have CoffeeScript output a line as raw javascript?
Asked Answered
K

2

6

Is there a way to tell CoffeeScript to just ignore a certain line and output it as is?

I want this line to be included in the resulting javascript

#import './blah/blah'

But CoffeeScript is compiling it as a comment so it ends up as

//import './blah/blah'

I need it to not do that because the script is being used for Apple's UIAutomation Instrument to drive iPhone UI. UIAutomation recognizes special #import statements but not if they are getting turned into javascript comments.

Kurrajong answered 20/2, 2012 at 8:16 Comment(0)
G
9

Enclose the statement with backicks (`)

`#import './blah/blah'`

You can use any JavaScript code that way.

Girosol answered 20/2, 2012 at 8:21 Comment(1)
Is there a way to prevent it from adding the semicolon at the end?Kurrajong
K
3

Doh, found the answer in the coffeescript docs

hi = `function() {
  return [document.title, "Hello JavaScript"].join(": ");
}`
Kurrajong answered 20/2, 2012 at 8:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.