Skip to content
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

--target es5 enables es6 class getters and setters #27

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -42,6 +42,10 @@ boolean option:

% browserify -t [ reactify --es6 ] main.js

es6 class getter and setter methods can be activated via `--target es5` option:

% browserify -t [ reactify --es6 --target es5 ] main.js

You can also configure it in package.json

```json
Expand Down
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -71,8 +71,12 @@ module.exports = function(file, options) {
});
}

var transformOptions = {
es5: options.target === 'es5'
};

function transformer(source) {
return transform(transformVisitors, source).code;
return transform(transformVisitors, source, transformOptions).code;
}

return process(file, isJSXFile, transformer);
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/main.es6-target-es5.jsx
@@ -0,0 +1,3 @@
class Foo {
get bar() {}
}
19 changes: 17 additions & 2 deletions test/reactify.js
Expand Up @@ -52,7 +52,7 @@ describe('reactify', function() {
});
});

describe('transforming files with extensions others than .js/.jsx', function() {
describe('transforming files with extensions other than .js/.jsx', function() {

it('activates via extension option', function(done) {
browserify('./fixtures/main.jsnox', {basedir: __dirname})
Expand Down Expand Up @@ -115,9 +115,24 @@ describe('reactify', function() {

});

describe('transforming with es5 as a target', function() {

it('activates via target option', function(done) {
browserify('./fixtures/main.es6-target-es5.jsx', {basedir: __dirname})
.transform({es6: true, target: 'es5'}, reactify)
.bundle(function(err, result) {
assert(!err);
assert(result);
assertContains(result, ' Object.defineProperty(Foo.prototype,"bar",{enumerable:true,configurable:true,get:function() {"use strict";');
done();
});
});

});

describe('transforming with custom visitors', function() {

it('activates via es6 option', function(done) {
it('activates via visitors option', function(done) {
browserify('./fixtures/main.es6-custom.jsx', {basedir: __dirname})
.transform({visitors: 'es6-module-jstransform/visitors'}, reactify)
.bundle(function(err, result) {
Expand Down