-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coffee Tags #4346
Coffee Tags #4346
Conversation
src/rewriter.coffee
Outdated
adjustCoffeeTags: -> | ||
@scanTokens (token, i, tokens) -> | ||
if token[0] is 'CT' | ||
f = generate 'IDENTIFIER', 'h'; f.spaced = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can’t merge in this PR if what it does is replace this new coffee tag literal with calls to a mysterious h
function that is not defined within CoffeeScript. That makes coffee tags dependant on some external library to supply this h
function in the global scope.
@shreeve please comment when the |
…unction $ coffee -s -p <<< '<!createRenderer!><a>"Hello..."' (function() { createRenderer('a', "Hello..."); }).call(this); $ coffee -s -p <<< '<a>"Hello..."' (function() { h('a', "Hello..."); }).call(this);
@GeoffreyBooth -- I've updated my local branch to include a new custom render function, using syntax like |
@shreeve Does this work with React? Can you show an example of how this could be used to implement a Coffee-style JSX? |
@GeoffreyBooth - Yes, this should work with React also. The code will simply call a function (by default |
In the above image, I'm actually showing the |
Can you please show how to achieve the examples in https://facebook.github.io/react/docs/react-without-jsx.html? Those are basically hello-world level. |
I can see this being a powerful tool, and obviously there is a lot of great
work in this branch. I like the idea of being able to treat HTML in a
coffee-esque way
I'm confused by a few things with this pull request, namely:
Why keep the html tag format at all? Why not add a new keyword and
everything indented from there is assumed to be either html or another
keyword?
And then the second question is that of context, how is object context
maintained through the chain?
The last real question is how do you see this fitting in to the ecosystem?
On Feb 17, 2017 9:47 AM, "Steve Shreeve" <[email protected]> wrote:
In the above image, I'm actually showing the coffee-tags syntax (which
allows the inline tags) and also something I called 'easytags' (which is a
way to easily specify tags, classes, ids, etc.). So, <@Conversations>
yields <div id="conversations">. Also, the <.messages> will yield <div
class="messages">.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4346 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABy6x-7Zzf1unj-c96zV0yp_ylomOgHaks5rdd1JgaJpZM4KeDGE>
.
|
Adding some personal opinion here as a ClojureScript programmer, who previously wrote CoffeeScript for medium-size React projects. I think it's not very wise to add the feature into the compiler, although the idea itself is quite cool. Here's the reasons. When I was using writing React, I can write virtual DOM in CoffeeScript, i.e. the {div = React.DOM}
render: ->
div {},
div {}, "text" That is valid JavaScript code in CoffeeScript, nothing more. And in ClojureScript, there is a similar situation that people want to code HTML DSLs like
The thing is it's just normal Clojure syntax that the library can transform the DSL at runtime. So no compiler is involved. I mean this feature is totally new syntax sugar for CoffeeScript, which involves some HTML knowledges. That will make CoffeeScript syntax depend on HTML stuffs. As it turned out it's actually a language extension, rather than core syntax. I would be worried if CoffeeScript ships such features. Well, being a ClojureScript guy. |
I’m not sure that this is something that should become part of the CoffeeScript compiler. On the one hand I like something that feels like an equivalent to JSX, to help prevent loss of mindshare for people who want to use React and feel like they should use JSX to do so; but on the other hand I feel like if something is going to be baked into the compiler, it needs to be abstract and able to handle any templating language. Not just JSX or HTML/React or Vue, but also Handlebars and Underscore templates, or anything else people might want to use. Not all of these things will have a render function with a Perhaps the real way that this should be implemented is via a plugin infrastructure, similar to how JSX is processed as a plugin for Babel. Then if @shreeve really just wants Vue templating integration, he can make just that; and someone using React or Handlebars or something else full-time on another project can tackle that integration as a plugin of its own. The compiler isn’t really designed in a very modular way, so I’m not sure how a plugin architecture would even look; or maybe there could be some kind of preprocessor, similar to how This also needs to be built on top of the |
As far as I know, all experimental or non-standard JavaScript syntax (including JSX) is hard-coded into Babylon, and just have on/off switches (I think the same is true for "all" JavaScript parsers). There are no "parser plugins": babel/babel#1351. Just sayin'. |
I think I've said this when it was proposed before, but... CoffeeScript should not be a language that mixes two different alien syntaxes together. JSX is useful, and compelling conceptually, but hideous syntactically. It would be extremely unCoffeeScripty to munge and HTML-ish syntax into what we already have. |
Closing for now. I think if this can be reimplemented as a plugin that sits atop CoffeeScript, similar to how |
@jashkenas I know what you're saying but things like typescript also have native JSX support. Its an absolute shame that implementing something like JSX as a pluginis kinda hard for none parser/grammer experts. And since CSJX is deprecated this really really forces me finally to move to babel, but i still feel completely silly writing so much babel code just because i want to use JSX. Is there really no option to include JSX? |
See https://facebook.github.io/react/docs/react-without-jsx.html: e = React.createElement
ReactDOM.render(
e('div', null, 'Hello World'),
document.getElementById('root')
) I’ve also seen people make shortcuts for each element they want to use: div = (props, children) ->
React.createElement 'div', props, children
ReactDOM.render(
div(null, 'Hello World'),
document.getElementById('root')
) If anything, this looks more Coffee-like than interspersing HTML tags in your code. And it’s fully supported by Facebook and React. |
I know that this exists, but its just not cutting it IMHO. CJSX is the only thing that comes close. Is there someway to hook in to the lexer/compiler as a plugin? Can’t seem to find any documentation on it.
… On Apr 10, 2017, at 14:56, Geoffrey Booth ***@***.***> wrote:
See https://facebook.github.io/react/docs/react-without-jsx.html <https://facebook.github.io/react/docs/react-without-jsx.html>:
e = React.createElement
ReactDOM.render(
e('div', null, 'Hello World'),
document.getElementById('root')
)
I’ve also seen people make shortcuts for each element they want to use:
div = (props, children) ->
React.createElement 'div', props, children
ReactDOM.render(
div(null, 'Hello World'),
document.getElementById('root')
)
If anything, this looks more Coffee-like than interspersing HTML tags in your code. And it’s fully supported by Facebook and React.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#4346 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AASgH50MHUsE157TO4W7uDxg1R4-soPOks5ruoltgaJpZM4KeDGE>.
|
I would maybe approach this the way Illiterate does. Illiterate is an implementation of “literate anything”, inspired by Literate CoffeeScript. So Literate CoffeeScript treats indented code blocks as CoffeeScript and non-indented lines as Markdown comments. Illiterate takes this one step further, treating indented code blocks as code (language agnostic) and non-indented lines as Markdown comments. Illiterate doesn’t try to transpile the code blocks (i.e. convert CoffeeScript code to JavaScript code); it just outputs a new file that has all the “comment” lines removed, so that some other tool can compile the “code” lines. If you can figure out how to recognize the “JSX” lines separate from the CoffeeScript lines, you could create a fork of Illiterate that works similarly. For example, any line that begins with A dumb way to separate the JSX lines from the Coffee lines is to require open/close comments, like |
CoffeeTags
{div, table, th, tr} = React.DOM
)<div.active@menu>
yields<div class="active" id="menu">
div()
, you can just use<div>
)<span.note!> "Note: #{text}"
)div
(i.e. -<>
,<.note>
, and<.active@sidebar!>
are all valid)className: 'foo'
)div null, "Hello"
)"h#{ level }">
can produce<h3>
)Example
CoffeeScript source
CoffeeScript output
An example component (this one uses VueJS)
It's important to note that, just by adding a new legal token to
CoffeeScript
, this is totally validCoffeeScript
code (ie - there is no "transformation" step, it's just "normal"CoffeeScript
source):