Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Add support for cjsx #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/rig-mime-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import mimeTypes from 'mime-types';

const typesToRig = {
'text/typescript': 'ts',
'text/jade': 'jade'
'text/jade': 'jade',
'text/cjsx': 'cjsx'
};


/**
* Adds MIME types for types not in the mime-types package
*
*
* @private
*/
*/
export function init() {
_.each(Object.keys(typesToRig), (type) => {
let ext = typesToRig[type];
Expand Down
11 changes: 7 additions & 4 deletions test/compiler-valid-invalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import mimeTypes from 'mime-types';

const pfs = pify(fs);

const d = require('debug')('electron-compile:compiler-valid-invalid');

let allFixtureFiles = _.filter(
fs.readdirSync(path.join(__dirname, '..', 'test', 'fixtures')),
(x) => x.match(/invalid\./i));

let mimeTypesToTest = _.reduce(allFixtureFiles, (acc,x) => {
if (global.compilersByMimeType[mimeTypes.lookup(x) || '__nope__']) {
acc.push(mimeTypes.lookup(x));
}

return acc;
}, []);

Expand All @@ -27,7 +29,7 @@ const expectedMimeTypeSpecialCases = {

for (let mimeType of mimeTypesToTest) {
let klass = global.compilersByMimeType[mimeType];

describe(`The ${klass.name} class for ${mimeType}`, function() {
beforeEach(function() {
this.fixture = new klass();
Expand All @@ -47,7 +49,8 @@ for (let mimeType of mimeTypesToTest) {

let result = await this.fixture.compile(source, input, ctx);
let expectedMimeType = expectedMimeTypeSpecialCases[mimeType] || 'application/javascript';


d(result.code);
expect(result.mimeType).to.equal(expectedMimeType);

// NB: Jade doesn't do source maps
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/invalid.cjsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @cjsx React.DOM

React = require('react')

Car = React.createClass
render: ->
Vehicle doors={$$$} locked={isLocked()} data-colour="red" on>
<Parts.FrontSeat
<Parts.BackSeat
<p className="seat">Which seat can I take? {@props?.seat or 'none'}</p>
</Vehicle>

React.renderComponent <Car seat="front, obvs" />,
document.getElementById 'container'
14 changes: 14 additions & 0 deletions test/fixtures/valid.cjsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# @cjsx React.DOM

React = require('react')

Car = React.createClass
render: ->
<Vehicle doors={4} locked={isLocked()} data-colour="red" on>
<Parts.FrontSeat />
<Parts.BackSeat />
<p className="seat">Which seat can I take? {@props?.seat or 'none'}</p>
</Vehicle>

React.renderComponent <Car seat="front, obvs" />,
document.getElementById 'container'