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

Babel fixes #751

Merged
merged 5 commits into from
Jul 23, 2016
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
1 change: 0 additions & 1 deletion doc/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable no-console */

var Documentation = require('./model/Documentation');
var Component = require('../ui/Component');
var DocumentationReader = require('./DocumentationReader');
var importDocumentation = require('./model/importDocumentation');
var request = require('../util/request');
Expand Down
1 change: 0 additions & 1 deletion doc/generator/parseFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ Parser.Prototype = function() {
return nodes;
};

var STATIC_PROP = /(.+)\.static/;
var _typeTagMatcher = /^\s*(\{[^@][^{]+\})\s+([\w\/]+)\s+(.+)/;

/**
Expand Down
1 change: 0 additions & 1 deletion test/ui/Clipboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var Registry = require('../../util/Registry');
var ComponentRegistry = require('../../ui/ComponentRegistry');
var Clipboard = require('../../ui/Clipboard');
var DOMElement = require('../../ui/DOMElement');
var Component = require('../../ui/Component');
var StubSurface = require('./StubSurface');
var TestContainerEditor = require('./TestContainerEditor');

Expand Down
1 change: 0 additions & 1 deletion test/ui/Surface.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ var Registry = require('../../util/Registry');
var createAnnotation = require('../../model/transform/createAnnotation');
var DocumentSession = require('../../model/DocumentSession');
var SurfaceManager = require('../../ui/SurfaceManager');
var Component = require('../../ui/Component');

var TestContainerEditor = require('./TestContainerEditor');
var fixture = require('../fixtures/createTestArticle');
Expand Down
2 changes: 0 additions & 2 deletions test/ui/TextPropertyComponent.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"use strict";

var test = require('../test').module('ui/TextPropertyComponent');

var Component = require('../../ui/Component');
var TextPropertyComponent = require('../../ui/TextPropertyComponent');

var fixture = require('../fixtures/createTestArticle');
Expand Down
2 changes: 1 addition & 1 deletion ui/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var oo = require('../util/oo');
@class
*/

var Command = function(params) {
function Command(params) {
this.params = params || {};
this.name = this.params.name;
if (!this.name) {
Expand Down
23 changes: 5 additions & 18 deletions util/_bundleStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// worker for sub-process

var cloneDeep = require('lodash/cloneDeep');
var path = require('path');

process.on('message', function(paramStr) {
Expand All @@ -12,24 +13,10 @@ process.on('message', function(paramStr) {
// ATTENTION: if someone wants to use es6 in their project
// they must use node6 and have babel-plugin-transfprm-es2015-
// they must have babel-register and es2015 installed
if (params.es6 || params.jsx) {
var plugins = [];
if (params.es6) {
plugins = plugins.concat(require('./_es6-babel-plugins'));
}
if (params.jsx) {
plugins.push("syntax-jsx");
plugins.push(
[ "transform-react-jsx", {
// this will generate calls such as in
// $$(MyComp, props, ...children)
"pragma": "$$"
}]
);
}
require(path.join(params.rootDir, 'node_modules', 'babel-register'))({
plugins: plugins
});
if (params.babel) {
var babelParams = cloneDeep(params.babel);
var babelRegister = path.join(params.rootDir, 'node_modules', 'babel-register');
require(babelRegister)(babelParams);
}
var Configurator = require(configuratorPath);
var MainPackage = require(mainPackagePath);
Expand Down
36 changes: 0 additions & 36 deletions util/_es6-babel-plugins.js

This file was deleted.

55 changes: 7 additions & 48 deletions util/bundleJS.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,16 @@
'use strict';

var cloneDeep = require('lodash/cloneDeep');
var extend = require('lodash/extend');
var browserify = require('browserify');

module.exports = function bundleJS(params, cb) {
if (!params.sourcePath) throw new Error("'sourcePath' is required");
params = extend({
jsx: false,
es6: false,
cache: true,
}, params);
var opts = {
debug: true,
extensions: []
};
if (params.cache) {
opts.cache = {};
opts.packageCache = {};
}
if (params.jsx) {
opts.extensions.push('.jsx');
}
var opts = extend({}, params.browserify);
// console.log('#### browserify options', opts);
var b = browserify(opts).add(params.sourcePath);

var useBabelify = params.jsx || params.es6;
if (useBabelify) {
var plugins = [];
var presets = [];
if (params.jsx) {
plugins.push("syntax-jsx");
plugins.push(
[ "transform-react-jsx", {
// this will generate calls such as in
// $$(MyComp, props, ...children)
"pragma": "$$"
}]
);
}
if (params.es6 === true || params.es6 === "full") {
plugins = plugins.concat(require('./_es6-babel-plugins'));
} else if (params.es6 === "modules") {
plugins.push(
// support for es6 import/export
// Note: the rest of es6 is supported natively by chrome
["transform-es2015-modules-commonjs-simple", {
"noMangle": true,
"addExports": true
}]
);
}
b = b.transform("babelify", {
presets: presets,
plugins: plugins
});
if (params.babel) {
b = b.transform("babelify", cloneDeep(params.babel));
}
b.bundle(function(err, buf) {
if (err) {
Expand All @@ -61,4 +19,5 @@ module.exports = function bundleJS(params, cb) {
cb(null, buf);
}
});
}
};

1 change: 1 addition & 0 deletions util/bundleStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports = function(params, cb) {
else cb(null, result.css);
});
} else {
console.info('Bundling styles for package %s', params.mainPackagePath);
var cp = require('child_process');
var child = cp.fork(require.resolve('./_bundleStyles'));
child.on('message', function(resultStr) {
Expand Down
6 changes: 3 additions & 3 deletions util/oo.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ function _afterClassInitHook() {
extend(Function, Function) -> inheritance with prototype function
*/
function _extendClass() {
var ParentClass = this;
var ParentClass = this; // eslint-disable-line
// this ctor is used when extend is not provided with a constructor function.
function AnonymousClass() {
ParentClass.apply(this, arguments);
Expand Down Expand Up @@ -257,8 +257,8 @@ function _mixin(Clazz, mixin) {

function _createExtend(clazz) {
return function() {
return _extendClass.apply(clazz, arguments)
}
return _extendClass.apply(clazz, arguments);
};
}

function _makeExtensible(clazz) {
Expand Down
4 changes: 3 additions & 1 deletion util/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ server.serveJS = function(expressApp, route, sourcePath, options) {
var params = extend(options, { sourcePath: sourcePath });
expressApp.get(route, function(req, res) {
var startTime = Date.now();
console.log('### Serving %s using browserify', sourcePath);
bundleJS(params, function(err, buf) {
console.info('browserify finished after %s ms', Date.now()-startTime);
if (err) {
console.error('browserify failed:');
console.error(err.message);
} else {
console.info('browserify finished after %s ms', Date.now()-startTime);
res.status(200).send(buf);
}
});
Expand Down