Merge branch 'master' into top-secret

# Conflicts:
#	packages/babylon/src/options.js
#	src/acorn/plugins/flow.js
#	src/acorn/src/util.js
This commit is contained in:
Sebastian McKenzie 2015-07-11 21:04:33 +01:00
commit f9498d7a2d
34 changed files with 294 additions and 90 deletions

View File

@ -1,6 +1,6 @@
<p align="center">
<a href="https://babeljs.io/">
<img alt="babel" src="https://raw.githubusercontent.com/babel/logo/master/logo.png" width="546">
<img alt="babel" src="https://raw.githubusercontent.com/babel/logo/master/babel.png" width="546">
</a>
</p>

View File

@ -18,9 +18,9 @@ program.option("-p, --print [code]", "Evaluate script and print result");
program.option("-i, --ignore [regex]", "Ignore all files that match this regex when using the require hook");
program.option("-x, --extensions [extensions]", "List of extensions to hook into [.es6,.js,.es,.jsx]");
program.option("-r, --stage [stage]", "Enable support for specific ECMAScript stages");
program.option("-w, --whitelist [whitelist]", "Whitelist of transformers to ONLY use", util.list);
program.option("-b, --blacklist [blacklist]", "Blacklist of transformers to NOT use", util.list);
program.option("-o, --optional [optional]", "List of optional transformers to enable", util.list);
program.option("-w, --whitelist [whitelist]", "Whitelist of transformers separated by comma to ONLY use", util.list);
program.option("-b, --blacklist [blacklist]", "Blacklist of transformers separated by comma to NOT use", util.list);
program.option("-o, --optional [optional]", "List of optional transformers separated by comma to enable", util.list);
var pkg = require("../package.json");
program.version(pkg.version);

View File

@ -90,8 +90,8 @@ function ExportDeclaration(node, print) {
export function ImportDeclaration(node, print) {
this.push("import ");
if (node.isType) {
this.push("type ");
if (node.importKind === "type" || node.importKind === "typeof") {
this.push(node.importKind + " ");
}
var specfiers = node.specifiers;

View File

@ -592,8 +592,10 @@ export default class ClassTransformer {
pushInherits() {
if (!this.isDerived || this.pushedInherits) return;
// Unshift to ensure that the constructor inheritance is set up before
// any properties can be assigned to the prototype.
this.pushedInherits = true;
this.body.push(t.expressionStatement(t.callExpression(
this.body.unshift(t.expressionStatement(t.callExpression(
this.file.addHelper("inherits"),
[this.classRef, this.superName]
)));

View File

@ -15,7 +15,7 @@ export var metadata = {
export var visitor = {
ImportDeclaration(node, parent, scope, file) {
// flow type
if (node.isType) return;
if (node.importKind === "type" || node.importKind === "typeof") return;
var nodes = [];

View File

@ -41,7 +41,7 @@ export var visitor = {
},
ImportDeclaration(node) {
if (node.isType) this.dangerouslyRemove();
if (node.importKind === "type" || node.importKind === "typeof") this.dangerouslyRemove();
},
ExportDeclaration() {

View File

@ -1,6 +1,8 @@
"use strict";
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
var _Foo$prototype$test, _Foo$prototype$test2;
@ -17,8 +19,6 @@ var Test = (function (_Foo) {
(_Foo$prototype$test2 = _Foo.prototype.test).call.apply(_Foo$prototype$test2, [this, "test"].concat(babelHelpers.slice.call(arguments)));
}
babelHelpers.inherits(Test, _Foo);
Test.prototype.test = function test() {
var _Foo$prototype$test3, _Foo$prototype$test4;

View File

@ -1,6 +1,8 @@
"use strict";
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
babelHelpers.classCallCheck(this, Test);
@ -9,6 +11,5 @@ var Test = (function (_Foo) {
_Foo.prototype.test.whatever;
}
babelHelpers.inherits(Test, _Foo);
return Test;
})(Foo);

View File

@ -1,6 +1,8 @@
"use strict";
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
babelHelpers.classCallCheck(this, Test);
@ -9,8 +11,6 @@ var Test = (function (_Foo) {
_Foo.prototype.test.call(this);
}
babelHelpers.inherits(Test, _Foo);
Test.test = function test() {
return _Foo.wow.call(this);
};

View File

@ -1,23 +1,25 @@
"use strict";
var BaseController = (function (_Chaplin$Controller) {
babelHelpers.inherits(BaseController, _Chaplin$Controller);
function BaseController() {
babelHelpers.classCallCheck(this, BaseController);
_Chaplin$Controller.apply(this, arguments);
}
babelHelpers.inherits(BaseController, _Chaplin$Controller);
return BaseController;
})(Chaplin.Controller);
var BaseController2 = (function (_Chaplin$Controller$Another) {
babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another);
function BaseController2() {
babelHelpers.classCallCheck(this, BaseController2);
_Chaplin$Controller$Another.apply(this, arguments);
}
babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another);
return BaseController2;
})(Chaplin.Controller.Another);

View File

@ -1,12 +1,13 @@
"use strict";
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
babelHelpers.classCallCheck(this, Test);
_Foo.apply(this, arguments);
}
babelHelpers.inherits(Test, _Foo);
return Test;
})(Foo);

View File

@ -1,6 +1,8 @@
"use strict";
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
var _babelHelpers$get, _babelHelpers$get2;
@ -17,7 +19,6 @@ var Test = (function (_Foo) {
(_babelHelpers$get2 = babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this)).call.apply(_babelHelpers$get2, [this, "test"].concat(babelHelpers.slice.call(arguments)));
}
babelHelpers.inherits(Test, _Foo);
babelHelpers.createClass(Test, [{
key: "test",
value: function test() {

View File

@ -1,6 +1,8 @@
"use strict";
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
babelHelpers.classCallCheck(this, Test);
@ -9,6 +11,5 @@ var Test = (function (_Foo) {
babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).whatever;
}
babelHelpers.inherits(Test, _Foo);
return Test;
})(Foo);

View File

@ -1,6 +1,8 @@
"use strict";
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
babelHelpers.classCallCheck(this, Test);
@ -9,7 +11,6 @@ var Test = (function (_Foo) {
babelHelpers.get(Object.getPrototypeOf(Test.prototype), "test", this).call(this);
}
babelHelpers.inherits(Test, _Foo);
babelHelpers.createClass(Test, null, [{
key: "test",
value: function test() {

View File

@ -7,6 +7,8 @@ var Test = function Test() {
};
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
babelHelpers.classCallCheck(this, Foo);
@ -14,7 +16,6 @@ var Foo = (function (_Bar) {
this.state = "test";
}
babelHelpers.inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -1,6 +1,8 @@
"use strict";
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
babelHelpers.classCallCheck(this, Foo);
@ -11,6 +13,5 @@ var Foo = (function (_Bar) {
var _this = this;
}
babelHelpers.inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -1,10 +1,11 @@
"use strict";
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
babelHelpers.classCallCheck(this, Foo);
}
babelHelpers.inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -1,12 +1,13 @@
"use strict";
var TestEmpty = (function (_ref) {
babelHelpers.inherits(TestEmpty, _ref);
function TestEmpty() {
babelHelpers.classCallCheck(this, TestEmpty);
babelHelpers.get(Object.getPrototypeOf(TestEmpty.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(TestEmpty, _ref);
return TestEmpty;
})((function () {
function _class() {
@ -17,12 +18,13 @@ var TestEmpty = (function (_ref) {
})());
var TestConstructorOnly = (function (_ref2) {
babelHelpers.inherits(TestConstructorOnly, _ref2);
function TestConstructorOnly() {
babelHelpers.classCallCheck(this, TestConstructorOnly);
babelHelpers.get(Object.getPrototypeOf(TestConstructorOnly.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(TestConstructorOnly, _ref2);
return TestConstructorOnly;
})((function () {
function _class2() {
@ -33,12 +35,13 @@ var TestConstructorOnly = (function (_ref2) {
})());
var TestMethodOnly = (function (_ref3) {
babelHelpers.inherits(TestMethodOnly, _ref3);
function TestMethodOnly() {
babelHelpers.classCallCheck(this, TestMethodOnly);
babelHelpers.get(Object.getPrototypeOf(TestMethodOnly.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(TestMethodOnly, _ref3);
return TestMethodOnly;
})((function () {
function _class3() {
@ -53,12 +56,13 @@ var TestMethodOnly = (function (_ref3) {
})());
var TestConstructorAndMethod = (function (_ref4) {
babelHelpers.inherits(TestConstructorAndMethod, _ref4);
function TestConstructorAndMethod() {
babelHelpers.classCallCheck(this, TestConstructorAndMethod);
babelHelpers.get(Object.getPrototypeOf(TestConstructorAndMethod.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(TestConstructorAndMethod, _ref4);
return TestConstructorAndMethod;
})((function () {
function _class4() {
@ -73,12 +77,13 @@ var TestConstructorAndMethod = (function (_ref4) {
})());
var TestMultipleMethods = (function (_ref5) {
babelHelpers.inherits(TestMultipleMethods, _ref5);
function TestMultipleMethods() {
babelHelpers.classCallCheck(this, TestMultipleMethods);
babelHelpers.get(Object.getPrototypeOf(TestMultipleMethods.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(TestMultipleMethods, _ref5);
return TestMultipleMethods;
})((function () {
function _class5() {

View File

@ -1,21 +1,23 @@
"use strict";
var BaseController = (function (_Chaplin$Controller) {
babelHelpers.inherits(BaseController, _Chaplin$Controller);
function BaseController() {
babelHelpers.classCallCheck(this, BaseController);
babelHelpers.get(Object.getPrototypeOf(BaseController.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(BaseController, _Chaplin$Controller);
return BaseController;
})(Chaplin.Controller);
var BaseController2 = (function (_Chaplin$Controller$Another) {
babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another);
function BaseController2() {
babelHelpers.classCallCheck(this, BaseController2);
babelHelpers.get(Object.getPrototypeOf(BaseController2.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(BaseController2, _Chaplin$Controller$Another);
return BaseController2;
})(Chaplin.Controller.Another);

View File

@ -1,11 +1,12 @@
"use strict";
var Test = (function (_Foo) {
babelHelpers.inherits(Test, _Foo);
function Test() {
babelHelpers.classCallCheck(this, Test);
babelHelpers.get(Object.getPrototypeOf(Test.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(Test, _Foo);
return Test;
})(Foo);

View File

@ -14,14 +14,14 @@ function broken(x) {
if (true) {
var _ret = (function () {
var Foo = (function (_Bar) {
_inherits(Foo, _Bar);
function Foo() {
_classCallCheck(this, Foo);
_get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments);
}
_inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -1,12 +1,13 @@
"use strict";
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
babelHelpers.classCallCheck(this, Foo);
babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments);
this.bar = "foo";
}
babelHelpers.inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -1,6 +1,8 @@
"use strict";
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
var _temp;
@ -9,6 +11,5 @@ var Foo = (function (_Bar) {
foo((_temp = babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this), this.bar = "foo", _temp));
}
babelHelpers.inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -1,6 +1,8 @@
"use strict";
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
babelHelpers.classCallCheck(this, Foo);
@ -8,6 +10,5 @@ var Foo = (function (_Bar) {
this.bar = "foo";
}
babelHelpers.inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -1,26 +1,28 @@
"use strict";
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
babelHelpers.classCallCheck(this, _Foo);
babelHelpers.get(Object.getPrototypeOf(_Foo.prototype), "constructor", this).call(this);
}
babelHelpers.inherits(Foo, _Bar);
var _Foo = Foo;
Foo = bar(Foo) || Foo;
return Foo;
})(Bar);
var Foo2 = (function (_Bar2) {
babelHelpers.inherits(Foo2, _Bar2);
function Foo2() {
babelHelpers.classCallCheck(this, _Foo2);
babelHelpers.get(Object.getPrototypeOf(_Foo2.prototype), "constructor", this).call(this);
}
babelHelpers.inherits(Foo2, _Bar2);
var _Foo2 = Foo2;
Foo2 = bar(Foo2) || Foo2;
return Foo2;

View File

@ -1,6 +1,8 @@
"use strict";
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo(options) {
babelHelpers.classCallCheck(this, Foo);
@ -11,6 +13,5 @@ var Foo = (function (_Bar) {
babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).call(this, parentOptions);
}
babelHelpers.inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -9,12 +9,13 @@ var _ref = React.createElement(
);
var App = (function (_React$Component) {
babelHelpers.inherits(App, _React$Component);
function App() {
babelHelpers.classCallCheck(this, App);
babelHelpers.get(Object.getPrototypeOf(App.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(App, _React$Component);
babelHelpers.createClass(App, [{
key: "render",
value: function render() {

View File

@ -7,12 +7,13 @@ Object.defineProperty(exports, "__esModule", {
var _store = require("./store");
var Login = (function (_React$Component) {
babelHelpers.inherits(Login, _React$Component);
function Login() {
babelHelpers.classCallCheck(this, Login);
babelHelpers.get(Object.getPrototypeOf(Login.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(Login, _React$Component);
babelHelpers.createClass(Login, [{
key: "getForm",
value: function getForm() {

View File

@ -1,11 +1,12 @@
"use strict";
var Foo = (function (_Bar) {
babelHelpers.inherits(Foo, _Bar);
function Foo() {
babelHelpers.classCallCheck(this, Foo);
babelHelpers.get(Object.getPrototypeOf(Foo.prototype), "constructor", this).apply(this, arguments);
}
babelHelpers.inherits(Foo, _Bar);
return Foo;
})(Bar);

View File

@ -95,11 +95,12 @@ export function getOptions(opts) {
options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt];
if (Array.isArray(options.onToken)) {
let tokens = options.onToken;
options.onToken = (token) => tokens.push(token);
let tokens = options.onToken
options.onToken = (token) => tokens.push(token)
}
if (Array.isArray(options.onComment)) {
options.onComment = pushComment(options, options.onComment)
}
if (Array.isArray(options.onComment))
options.onComment = pushComment(options, options.onComment);
return options;
}

View File

@ -784,19 +784,19 @@ export default function (instance) {
instance.extend("parseImportSpecifiers", function (inner) {
return function (node) {
node.isType = false;
if (this.isContextual("type")) {
var startPos = this.start, startLoc = this.startLoc;
var typeId = this.parseIdent();
if ((this.type === tt.name && this.value !== "from") || this.type === tt.braceL || this.type === tt.star) {
node.isType = true;
} else {
node.specifiers.push(this.parseImportSpecifierDefault(typeId, startPos, startLoc));
if (this.isContextual("from")) return;
this.eat(tt.comma);
node.importKind = "value"
var kind =
(this.type === tt._typeof ? "typeof" :
(this.isContextual("type") ? "type" : null))
if (kind) {
var lh = this.lookahead()
if ((lh.type === tt.name && lh.value !== "from") || lh.type === tt.braceL || lh.type === tt.star) {
this.next()
node.importKind = kind
}
}
inner.call(this, node);
inner.call(this, node)
};
});

View File

@ -6728,13 +6728,49 @@ var fbTestFixture = {
end: { line: 1, column: 26 }
}
},
isType: true,
importKind: 'type',
range: [0, 27],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 27 }
}
},
'import typeof foo from "bar";': {
type: 'ImportDeclaration',
specifiers: [{
type: 'ImportDefaultSpecifier',
local: {
type: 'Identifier',
name: 'foo',
range: [14, 17],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 17 }
}
},
range: [14, 17],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 17 }
}
}],
source: {
type: 'Literal',
value: 'bar',
raw: '"bar"',
range: [23, 28],
loc: {
start: { line: 1, column: 23 },
end: { line: 1, column: 28 }
}
},
importKind: 'typeof',
range: [0, 29],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 29 }
}
},
'import type {foo, bar} from "baz";': {
type: 'ImportDeclaration',
specifiers: [{
@ -6798,17 +6834,26 @@ var fbTestFixture = {
end: { line: 1, column: 33 }
}
},
isType: true,
importKind: 'type',
range: [0, 34],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 34 }
}
},
'import type {foo as bar} from "baz";': {
'import type {foo, bar} from "baz";': {
type: 'ImportDeclaration',
specifiers: [{
type: 'ImportSpecifier',
local: {
type: 'Identifier',
name: 'foo',
range: [13, 16],
loc: {
start: { line: 1, column: 13 },
end: { line: 1, column: 16 }
}
},
imported: {
type: 'Identifier',
name: 'foo',
@ -6818,36 +6863,97 @@ var fbTestFixture = {
end: { line: 1, column: 16 }
}
},
range: [13, 16],
loc: {
start: { line: 1, column: 13 },
end: { line: 1, column: 16 }
}
}, {
type: 'ImportSpecifier',
local: {
type: 'Identifier',
name: 'bar',
range: [20, 23],
range: [18, 21],
loc: {
start: { line: 1, column: 20 },
end: { line: 1, column: 23 }
start: { line: 1, column: 18 },
end: { line: 1, column: 21 }
}
},
range: [13, 23],
imported: {
type: 'Identifier',
name: 'bar',
range: [18, 21],
loc: {
start: { line: 1, column: 13 },
end: { line: 1, column: 23 }
start: { line: 1, column: 18 },
end: { line: 1, column: 21 }
}
},
range: [18, 21],
loc: {
start: { line: 1, column: 18 },
end: { line: 1, column: 21 }
}
}],
source: {
type: 'Literal',
value: 'baz',
raw: '"baz"',
range: [30, 35],
range: [28, 33],
loc: {
start: { line: 1, column: 30 },
end: { line: 1, column: 35 }
start: { line: 1, column: 28 },
end: { line: 1, column: 33 }
}
},
isType: true,
range: [0, 36],
importKind: 'type',
range: [0, 34],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 36 }
end: { line: 1, column: 34 }
}
},
'import typeof {foo as bar} from "baz";': {
type: 'ImportDeclaration',
specifiers: [{
type: 'ImportSpecifier',
imported: {
type: 'Identifier',
name: 'foo',
range: [15, 18],
loc: {
start: { line: 1, column: 15 },
end: { line: 1, column: 18 }
}
},
local: {
type: 'Identifier',
name: 'bar',
range: [22, 25],
loc: {
start: { line: 1, column: 22 },
end: { line: 1, column: 25 }
}
},
range: [15, 25],
loc: {
start: { line: 1, column: 15 },
end: { line: 1, column: 25 }
}
}],
source: {
type: 'Literal',
value: 'baz',
raw: '"baz"',
range: [32, 37],
loc: {
start: { line: 1, column: 32 },
end: { line: 1, column: 37 }
}
},
importKind: 'typeof',
range: [0, 38],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 38 }
}
},
'import type from "foo";': {
@ -6879,7 +6985,7 @@ var fbTestFixture = {
end: { line: 1, column: 22 }
}
},
isType: false,
importKind: 'value',
range: [0, 23],
loc: {
start: { line: 1, column: 0 },
@ -6940,7 +7046,7 @@ var fbTestFixture = {
end: { line: 1, column: 29 }
}
},
isType: false,
importKind: 'value',
range: [0, 30],
loc: {
start: { line: 1, column: 0 },
@ -6976,13 +7082,49 @@ var fbTestFixture = {
end: { line: 1, column: 37 }
}
},
isType: true,
importKind: 'type',
range: [0, 38],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 38 }
}
},
'import typeof * as namespace from "bar";': {
type: 'ImportDeclaration',
specifiers: [{
type: 'ImportNamespaceSpecifier',
local: {
type: 'Identifier',
name: 'namespace',
range: [19, 28],
loc: {
start: { line: 1, column: 19 },
end: { line: 1, column: 28 }
}
},
range: [14, 28],
loc: {
start: { line: 1, column: 14 },
end: { line: 1, column: 28 }
}
}],
source: {
type: 'Literal',
value: 'bar',
raw: '"bar"',
range: [34, 39],
loc: {
start: { line: 1, column: 34 },
end: { line: 1, column: 39 }
}
},
importKind: 'typeof',
range: [0, 40],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 40 }
}
},
},
'Array Types': {
'var a: number[]': {

View File

@ -0,0 +1,11 @@
class Foo {}
class Bar extends Foo {
methodA(){}
constructor(){
super();
}
methodB(){}
}

View File

@ -0,0 +1,21 @@
"use strict";
var Foo = function Foo() {
babelHelpers.classCallCheck(this, Foo);
};
var Bar = (function (_Foo) {
babelHelpers.inherits(Bar, _Foo);
Bar.prototype.methodA = function methodA() {};
function Bar() {
babelHelpers.classCallCheck(this, Bar);
_Foo.call(this);
}
Bar.prototype.methodB = function methodB() {};
return Bar;
})(Foo);