Skip to content

Commit 216fa2b

Browse files
committed
Final release, deprecation, codemod stuff
1 parent 710ec43 commit 216fa2b

File tree

5 files changed

+52
-10
lines changed

5 files changed

+52
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [5.0.0]
4+
- final release / deprecation
5+
- added opts for codemod use
6+
37
## [4.0.0]
48
- Replace `React.__spread` with `Object.assign` ([DawidJanczak](https://github.com/DawidJanczak))
59
- Allow spaces in spread attributes ([rechtar](https://github.com/rechtar))

README.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
# Coffeescript React JSX Transformer
22

3-
Provides support for an equivalent of JSX syntax in Coffeescript (called CJSX) so you can write your Facebook React components with the full awesomeness of Coffeescript. [Try it out](https://jsdf.github.io/coffee-react-transform/).
3+
# STATUS: DEPRECATED
44

5-
#### Status
5+
This tool is no longer maintained. If you need to transition your codebase from
6+
it, a codemod is available to do so: [cjsx-codemod](https://github.com/jsdf/cjsx-codemod)
67

7-
This project is seeking maintainers. If you are interested in becoming a maintainer [create an issue](https://github.com/jsdf/coffee-react-transform/issues). Pull requests will be reviewed and merged (time permitting), but this project is not currently under active development.
8+
This project started as a way for me to explore how JSX could fit into
9+
Coffeescript syntax, as a quickly hacked together prototype. While I never
10+
really promoted it, it quickly took on a life of its own, and before long people
11+
were asking for it to support all kinds of different use cases. On top of that I
12+
had no experience writing parsers, so the result is something with
13+
[insurmountable limitations](https://github.com/jsdf/coffee-react/issues/32).
14+
15+
As I eventually stopped using Coffeescript I ended up neglecting this project,
16+
but as people were using it I didn't want to kill it. I really should have,
17+
however, because it meant that people were using a crappy, ill-conceived,
18+
unmaintained tool. Now, long overdue, I'm putting it out to pasture.
19+
20+
Original readme follows:
21+
22+
Provides support for an equivalent of JSX syntax in Coffeescript (called CJSX) so you can write your React components with the full awesomeness of Coffeescript. [Try it out](https://jsdf.github.io/coffee-react-transform/).
823

924
#### Example
1025

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"coffee-react"
1010
],
1111
"author": "James Friend",
12-
"version": "4.0.0",
12+
"version": "5.0.0",
1313
"licenses": [
1414
{
1515
"type": "MIT",

src/serialiser.coffee

+28-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,26 @@ stringEscape = require './stringescape'
77

88
entityDecode = require './entitydecode'
99

10-
module.exports = exports = serialise = (parseTree) ->
11-
new Serialiser().serialise(parseTree)
10+
module.exports = exports = serialise = (parseTree, opts) ->
11+
new Serialiser().serialise(parseTree, opts)
12+
13+
DEFAULT_CREL_EXPR = '`${REACT}.createElement(${ELEMENT}, ${ARGS})`'
14+
15+
makeCreateElementTemplate = (pattern) ->
16+
eval """
17+
function template(REACT, ELEMENT, ARGS) {
18+
return #{pattern};
19+
}
20+
"""
21+
template
1222

1323
class Serialiser
14-
serialise: (parseTree) ->
24+
serialise: (parseTree, @opts = {}) ->
25+
@hasJSX = false
26+
@jsxExpression = makeCreateElementTemplate(
27+
@opts.jsxExpression || DEFAULT_CREL_EXPR
28+
)
29+
1530
if parseTree.children and
1631
parseTree.children.length and
1732
parseTree.children[0].type is $.CJSX_PRAGMA
@@ -25,7 +40,13 @@ class Serialiser
2540
else
2641
@reactObject = 'React'
2742

28-
@serialiseNode(parseTree)
43+
serialised = @serialiseNode(parseTree)
44+
45+
# hack to add extra stuff at the top if JSX was used
46+
if @opts.jsxImport and @hasJSX
47+
"#{@opts.jsxImport}\n#{serialised}"
48+
else
49+
serialised
2950

3051
serialiseNode: (node) ->
3152
unless nodeSerialisers[node.type]?
@@ -183,7 +204,9 @@ nodeSerialisers =
183204
element = node.value
184205
else
185206
element = '"'+node.value+'"'
186-
"#{@reactObject}.createElement(#{element}, #{joinList(serialisedChildren)})"
207+
208+
@hasJSX = true # hack
209+
@jsxExpression(@reactObject, element, joinList(serialisedChildren))
187210

188211
CJSX_COMMENT: (node) ->
189212
''

src/transformer.coffee

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Parser = require './parser'
33
serialise = require './serialiser'
44

55
module.exports.transform = (code, opts) ->
6-
serialise(new Parser().parse(code, opts))
6+
serialise(new Parser().parse(code, opts), opts)

0 commit comments

Comments
 (0)