Compare commits

...

69 Commits

Author SHA1 Message Date
Sebastian McKenzie
f5d9636353 v4.5.1 2015-02-25 22:55:50 +11:00
Sebastian McKenzie
a7f713ef5a remove jscs since it doesn't like arrow functions :( 2015-02-25 22:53:54 +11:00
Sebastian McKenzie
ba11069b1c utilise arrow functions omfg i love ES6 holy shit 2015-02-25 22:52:22 +11:00
Sebastian McKenzie
c13f8a3f50 update contributing guide 2015-02-25 22:43:40 +11:00
Sebastian McKenzie
339bd2b6d9 self-host #443 2015-02-25 22:36:23 +11:00
Sebastian McKenzie
a2843a5cb8 4.5.0 2015-02-25 22:03:38 +11:00
Sebastian McKenzie
c31832439a v4.5.0 2015-02-25 22:02:23 +11:00
Sebastian McKenzie
b7f19221a9 fix rc json error message 2015-02-25 22:00:32 +11:00
Sebastian McKenzie
46a37f4672 fix linting errors 2015-02-25 21:59:59 +11:00
Sebastian McKenzie
cfe2c19a02 fix linting errors 2015-02-25 21:57:49 +11:00
Sebastian McKenzie
649d91ef25 add 4.5.0 changelog 2015-02-25 21:56:23 +11:00
Sebastian McKenzie
4d72bffa30 add --copy-files bin/babel flag 2015-02-25 21:56:19 +11:00
Sebastian McKenzie
5889233adc rejigger path traversal class for es6ification 2015-02-25 21:50:40 +11:00
Sebastian McKenzie
7bb98352df add .babelrc - fixes #351 2015-02-25 21:49:48 +11:00
Sebastian McKenzie
12ebeed7c6 add missing extension to umd-strict formatter... - fixes #890 2015-02-25 19:10:20 +11:00
Sebastian McKenzie
7d87e52377 rejigger strict directives transformer logic so they're included in the body before module formatters are ran - @jayphelps 2015-02-25 17:20:23 +11:00
Sebastian McKenzie
2bab285970 temporarily disable own binding identification in nameMethod helper - fixes #871 2015-02-25 11:07:51 +11:00
Sebastian McKenzie
00651e671e don't copy over non-compilable files - fixes #888 2015-02-25 10:59:26 +11:00
Sebastian McKenzie
37588a6ceb 4.4.6 2015-02-24 22:17:46 +11:00
Sebastian McKenzie
a45d6960da v4.4.6 2015-02-24 22:17:12 +11:00
Sebastian McKenzie
b13aa41a75 fixing linting error 2015-02-24 22:15:27 +11:00
Sebastian McKenzie
20a4ed6140 add 4.4.6 changelog 2015-02-24 22:14:34 +11:00
Sebastian McKenzie
c256e060b3 Merge branch 'master' of github.com:6to5/6to5 2015-02-24 22:11:33 +11:00
Sebastian McKenzie
bef315efd6 fix up JSXElement alias keys 2015-02-24 22:11:25 +11:00
Sebastian McKenzie
2ec5390b63 bump core-js 2015-02-24 22:11:18 +11:00
Sebastian McKenzie
f4c9dd8768 Merge pull request #881 from sindresorhus/bump-chalk
bump `chalk`
2015-02-24 22:06:05 +11:00
Sindre Sorhus
510c7a3e60 bump chalk
https://github.com/sindresorhus/chalk/releases/tag/v1.0.0
2015-02-24 16:03:00 +07:00
Sebastian McKenzie
3ce9508a1c bump core-js @zloirock 2015-02-24 14:16:29 +11:00
Sebastian McKenzie
717ef280f7 clean up #870 2015-02-24 11:20:04 +11:00
Sebastian McKenzie
8c5e7cf272 Merge pull request #870 from neVERberleRfellerER/fix-extends-anon-class
fix extends with empty anonymous base class
2015-02-24 11:18:18 +11:00
Ondrej Kraus
811a843be9 add tests for extends of anonymous classes 2015-02-24 01:01:05 +01:00
Ondrej Kraus
b7c297bb89 remove anonymous class constructor name in specific case
Name of anonymous class constructor is not needed when it contains
exactly one method that is not construtor, because constructor
will be assigned to variable in closure.
2015-02-24 01:01:02 +01:00
Sebastian McKenzie
b7342ef4ea move es6.arrowFunctions transformer - fixes #874 2015-02-24 10:31:11 +11:00
Sebastian McKenzie
1a899f5e77 move attribute whitespace handling to JSXAttribute enter - fixes #872 2015-02-24 09:48:10 +11:00
Sebastian McKenzie
f2eb1643c0 throw deprecation error for @jsx React.DOM usage and crawl all comments for pragmas - fixes #876 2015-02-24 09:38:16 +11:00
neVERberleRfellerER
9621d1bbeb remove unnecessary derived class constructor name 2015-02-23 17:39:42 +01:00
Ondrej Kraus
3cf7b2b761 add name to constructor of extended anonymous class 2015-02-23 17:19:41 +01:00
Sebastian McKenzie
ae8b1e242b remove illegal left for of test 2015-02-23 21:36:42 +11:00
Sebastian McKenzie
eea48f866d allow MemberExpressions in for-of head 2015-02-23 21:31:57 +11:00
Sebastian McKenzie
84d2d7b7d4 add 4.4.5 changelog 2015-02-23 11:11:24 +11:00
Sebastian McKenzie
ea30a619dd bump regenerator-babel 2015-02-23 11:11:19 +11:00
Sebastian McKenzie
87a201db22 4.4.5 2015-02-22 23:27:02 +11:00
Sebastian McKenzie
bcc86c47bc v4.4.5 2015-02-22 23:26:01 +11:00
Sebastian McKenzie
b6df9b583b 4.4.4 2015-02-22 23:23:38 +11:00
Sebastian McKenzie
52ea7b5f59 always use closure wrap - fixes #864 2015-02-22 23:23:34 +11:00
Sebastian McKenzie
7bff8239a1 v4.4.4 2015-02-22 22:50:02 +11:00
Sebastian McKenzie
04d79c1740 fix array unpacking test 2015-02-22 22:46:27 +11:00
Sebastian McKenzie
e387da7c2b upgrade acorn-babel 2015-02-22 22:42:17 +11:00
Sebastian McKenzie
53cf453480 add 4.4.4 changelog 2015-02-22 22:40:18 +11:00
Sebastian McKenzie
341528ee4a fix linting errors 2015-02-22 22:37:51 +11:00
Sebastian McKenzie
5f6808ba92 don't transform flow module nodes 2015-02-22 22:35:47 +11:00
Sebastian McKenzie
0b2f1fedcb don't unpack array when the pattern contains more elements than the corresponding array expression 2015-02-22 22:35:38 +11:00
Sebastian McKenzie
c3c94f0a4a fix options argument to vm.runInThisContext 2015-02-22 22:35:04 +11:00
Sebastian McKenzie
f2d60aab9e optimise named functions depending on whether they contain an assignment/reference - #861 2015-02-22 21:35:08 +11:00
Sebastian McKenzie
ab6bb35a4f make line-numbers and js-tokens versions fixed 2015-02-22 20:55:09 +11:00
Sebastian McKenzie
e11b943514 revert to old named function wrapper - fixes #861 2015-02-22 20:54:47 +11:00
Sebastian McKenzie
b44a6eb297 remove is-keyword-js in favor of esutils #856 2015-02-22 10:51:27 +11:00
Sebastian McKenzie
f3288ddb1f Merge branch 'lydell-error-syntax-highlighting' 2015-02-22 10:49:30 +11:00
Simon Lydell
476aa44a90 improve syntax highlighting in error messages
- Support hexadecimal, octal and binary number literals, template strings, and
  tokenize everything more robustly in general.
- Tokens spanning over several lines (such as multiline strings and comments) no
  longer leak their color into the line number gutter.
- The color scheme is preserved.
- The line numbers are now right-aligned instead of left-aligned, since that's
  how practically every editor does it.
- Superfluos space in the line number gutter has been removed.
2015-02-21 21:20:52 +01:00
Sebastian McKenzie
c5589e9336 Merge pull request #853 from meandmycode/master
build: ensure bootstrap works on windows
2015-02-21 21:43:49 +11:00
Stephen Taylor
404eb2f972 build: ensure bootstrap works on windows 2015-02-21 10:17:28 +00:00
Sebastian McKenzie
366257915e advise users to visit the gitter room before creating an issue in the readme 2015-02-21 19:17:48 +11:00
Sebastian McKenzie
e0cd9bdbe3 4.4.3 2015-02-21 19:14:26 +11:00
Sebastian McKenzie
39854dc088 v4.4.3 2015-02-21 18:13:10 +11:00
Sebastian McKenzie
81132aa942 add 4.4.3 changelog 2015-02-21 18:08:32 +11:00
Sebastian McKenzie
5ba2e6254b check if iterator has a return method before calling it when breaking in a for...of - #838 2015-02-21 18:00:43 +11:00
Sebastian McKenzie
61ea720637 don't traverse into replacement breaks in for-of transformer - thanks @zloirock 2015-02-21 17:55:38 +11:00
Sebastian McKenzie
55357a331d rename selfContained transformer to runtime 2015-02-21 17:20:59 +11:00
Sebastian McKenzie
5deaeba3a0 4.4.2 2015-02-21 14:31:52 +11:00
306 changed files with 1105 additions and 810 deletions

View File

@@ -1,5 +1,6 @@
{
"experimental": true,
"playground": true,
"loose": true
"loose": true,
"blacklist": ["es6.tailCall"]
}

1
.gitignore vendored
View File

@@ -13,3 +13,4 @@ dist
.package.json
packages/babel-runtime/*.js
packages/babel-runtime/regenerator/*.js
lib

58
.jscsrc
View File

@@ -1,58 +0,0 @@
{
"excludeFiles": ["lib/babel/transformation/templates"],
"disallowSpacesInNamedFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowSpaceAfterObjectKeys": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowSpaceBeforePostfixUnaryOperators": true,
"disallowSpaceBeforeBinaryOperators": [
","
],
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowYodaConditions": true,
"disallowKeywords": [ "with" ],
"disallowMultipleLineBreaks": true,
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": true,
"requireBlocksOnNewline": 1,
"requireCommaBeforeLineBreak": true,
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true,
"requireSpacesInForStatement": true,
"requireCurlyBraces": [
"do"
],
"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"case",
"return",
"try",
"catch",
"typeof",
"function"
],
"validateLineBreaks": "LF",
"validateQuoteMarks": "\"",
"validateIndentation": 2
}

View File

@@ -1 +1 @@
lib/babel/transformation/templates
src/babel/transformation/templates

View File

@@ -13,3 +13,4 @@ CHANGELOG.md
coverage
vendor
packages
src

View File

@@ -13,6 +13,50 @@ _Note: Gaps between patch versions are faulty/broken releases._
See [CHANGELOG - 6to5](CHANGELOG-6to5.md) for the pre-4.0.0 version changelog.
## 4.5.0
* **New Feature**
* Add `.babelrc` support.
* **Bug Fix**
* Move use strict directives to the module formatter bodies.
* **Internal**
* Make default `bin/babel` behaviour to ignore non-compilable files and add a `--copy-files` flag to revert to the old behaviour.
## 4.4.6
* **Bug Fix**
* Fix extending a class expression with no methods/only constructor. Thanks [@neVERberleRfellerER](https://github.com/neVERberleRfellerER)!
* Allow `MemberExpression` as a valid `left` of `ForOfStatement`.
* **Polish**
* Throw an error when people try and transpile code with the `@jsx React.DOM` pragma as it conflicts with the custom jsx constructo method detection.
* Crawl all comments for `@jsx` pragma.
* **Internal**
* Upgrade `chalk`.
* Upgrade `core-js`.
## 4.4.5
* **Internal**
* Remove function self reference optimisation.
## 4.4.4
* **Bug Fix**
* Handle inferred function ids to be reassigned and deopt to a slower but working equivalent.
* Don't unpack array patterns that have more elements than their right hand array expression.
* **Polish**
* Improve syntax highlighting in the code frame. Thanks [@lydell](https://github.com/lydell)!
* **Internal**
* Upgrade `acorn-babel`.
## 4.4.3
* **Bug Fix**
* Fix `for...of` iterator break returns being duplicated.
* Only call `return` on the iterator if it exists.
* **Internal**
* Rename `selfContained` transformer to `runtime`.
## 4.4.2
* **New Feature**

View File

@@ -10,6 +10,49 @@ pollutes the git tree.
## Developing
#### Setup
```sh
$ git clone https://github.com/babel/babel
$ cd babel
$ make bootstrap
```
Then you need to run:
```sh
$ make watch-core
```
This will compile babel and then sit in the background and on file modification
recompile the necessary files.
#### Running tests
You can run tests via:
```sh
$ make test
```
This will usually take around two minutes as it's compiling the entire
[test262](https://github.com/tc39/test262) test suite and validating it's AST.
This is mostly overkill and you can limit the tests to a select few by directly
running them with `mocha`:
```sh
$ mocha test/transformation.js
```
#### Linting
Please follow the correct code style, this ensures that the code is consistent
and increases maintainability.
```sh
$ make lint
```
#### Workflow
* Fork the repository
@@ -18,8 +61,7 @@ pollutes the git tree.
* Link your forked clone (`npm link`)
* Develop your changes ensuring you're fetching updates from upstream often
* Ensure the test are passing (`make test`)
* Create new pull request explaining your proposed change or reference an issue
in your commit message
* Create new pull request explaining your proposed change or reference an issue in your commit message
#### Code Standards
@@ -43,11 +85,3 @@ pollutes the git tree.
* **Declaration**
* No unused variables
* No pollution of global variables and prototypes
## Testing
$ make test
## Linting
$ make lint

View File

@@ -4,7 +4,6 @@ UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs
#UGLIFY_CMD = node_modules/uglify-js/bin/uglifyjs --mangle sort
JSHINT_CMD = node_modules/jshint/bin/jshint
MOCHA_CMD = node_modules/mocha/bin/_mocha
JSCS_CMD = node_modules/jscs/bin/jscs
BABEL_CMD = node_modules/babel/bin/babel
export NODE_ENV = test
@@ -12,13 +11,14 @@ export NODE_ENV = test
.PHONY: clean test test-cov test-clean lint test-travis test-simple test-all test-browser publish build bootstrap publish-core publish-runtime build-core watch-core
build-core:
#node $(BABEL_CMD) src --out-dir lib
node $(BABEL_CMD) src --out-dir lib --copy-files
watch-core:
#node $(BABEL_CMD) src --out-dir lib --watch
node $(BABEL_CMD) src --out-dir lib --watch --copy-files
build:
mkdir -p dist
make build-core
node tools/cache-templates
@@ -37,8 +37,7 @@ clean:
rm -rf coverage templates.json test/tmp dist
lint:
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js lib bin
$(JSCS_CMD) lib bin
$(JSHINT_CMD) --reporter node_modules/jshint-stylish/stylish.js src bin
test-clean:
rm -rf test/tmp
@@ -119,5 +118,5 @@ publish-core:
bootstrap:
npm install
git submodule update --init
cd vendor/regenerator; npm install
cd vendor/compat-table; npm install object-assign
cd vendor/regenerator && npm install
cd vendor/compat-table && npm install object-assign

View File

@@ -9,8 +9,9 @@
</p>
<p align="center">
For more information view the <a href="https://babeljs.io/">documentation</a>. For
support visit the <a href="https://gitter.im/babel/babel">gitter room</a>.
For more information view the <a href="https://babeljs.io/">documentation</a>. For questions
and support please visit the <a href="https://gitter.im/babel/babel">gitter room</a> before
creating an issue.
</p>
<p align="center">

View File

@@ -50,7 +50,10 @@ var _eval = function (code, filename) {
experimental: program.experimental,
playground: program.playground
}).code;
return vm.runInThisContext(code, filename);
return vm.runInThisContext(code, {
filename: filename
});
};
if (program.eval || program.print) {

View File

@@ -43,7 +43,7 @@ module.exports = function (commander, filenames, opts) {
var src = path.join(dirname, filename);
if (util.canCompile(filename)) {
write(src, filename);
} else {
} else if (commander.copyFiles) {
outputFileSync(path.join(commander.outDir, filename), fs.readFileSync(src));
}
});
@@ -64,7 +64,7 @@ module.exports = function (commander, filenames, opts) {
_.each(["add", "change"], function (type) {
watcher.on(type, function (filename) {
var relative = path.relative(dirname, filename) || filename;
write(filename, relative);
if (util.canCompile(filename)) write(filename, relative);
});
});
});

View File

@@ -28,6 +28,7 @@ commander.option("-M, --module-ids", "Insert module id in modules", false);
commander.option("-R, --react-compat", "Makes the react transformer produce pre-v0.12 code");
commander.option("--keep-module-id-extensions", "Keep extensions when generating module ids", false);
commander.option("-a, --auxiliary-comment [comment]", "Comment text to prepend to all auxiliary code");
commander.option("-D, --copy-files", "When compiling a directory copy over non-compilable files");
commander.on("--help", function () {
var outKeys = function (title, obj) {

View File

@@ -1,10 +1,11 @@
var readdir = require("fs-readdir-recursive");
var index = require("./index");
var babel = require("../../lib/babel/api/node");
var util = require("../../lib/babel/util");
var path = require("path");
var fs = require("fs");
var _ = require("lodash");
var resolveRc = require("../../lib/babel/api/register/resolve-rc");
var readdir = require("fs-readdir-recursive");
var index = require("./index");
var babel = require("../../lib/babel/api/node");
var util = require("../../lib/babel/util");
var path = require("path");
var fs = require("fs");
var _ = require("lodash");
exports.readdirFilter = function (filename) {
return readdir(filename).filter(function (filename) {
@@ -23,6 +24,7 @@ exports.addSourceMappingUrl = function (code, loc) {
exports.transform = function (filename, code, opts) {
opts = _.defaults(opts || {}, index.opts);
opts.filename = filename;
resolveRc(filename, opts);
var result;
try {

View File

@@ -1,78 +0,0 @@
// syntax highlighting based on https://github.com/dominictarr/ansi-highlight by the fantastic Dominic Tarr
var repeating = require("repeating");
var tokenize = require("js-tokenizer");
var chalk = require("chalk");
var defs = {
string1: "red",
string2: "red",
punct: ["white", "bold"],
curly: "green",
parens: ["blue", "bold"],
square: ["yellow"],
name: "white",
keyword: ["cyan"],
number: "magenta",
regexp: "magenta",
comment1: "grey",
comment2: "grey"
};
var highlight = function (text) {
var colorize = function (str, col) {
if (!col) return str;
if (Array.isArray(col)) {
col.forEach(function (col) {
str = chalk[col](str);
});
} else {
str = chalk[col](str);
}
return str;
};
return tokenize(text, true).map(function (str) {
var type = tokenize.type(str);
return colorize(str, defs[type]);
}).join("");
};
module.exports = function (lines, lineNumber, colNumber) {
colNumber = Math.max(colNumber, 0);
if (chalk.supportsColor) {
lines = highlight(lines);
}
lines = lines.split(/\r\n|[\n\r\u2028\u2029]/);
var start = Math.max(lineNumber - 3, 0);
var end = Math.min(lines.length, lineNumber + 3);
var width = (end + "").length;
if (!lineNumber && !colNumber) {
start = 0;
end = lines.length;
}
return "\n" + lines.slice(start, end).map(function (line, i) {
var curr = i + start + 1;
var gutter = curr === lineNumber ? "> " : " ";
var sep = curr + repeating(" ", width + 1);
gutter += sep + "| ";
var str = gutter + line;
if (colNumber && curr === lineNumber) {
str += "\n";
str += repeating(" ", gutter.length - 2);
str += "|" + repeating(" ", colNumber) + "^";
}
return str;
}).join("\n");
};

View File

@@ -1,53 +0,0 @@
"use strict";
var util = require("../../util");
var t = require("../../types");
var visitor = {
enter: function (node, parent, scope, state) {
// check if this node is an identifier that matches the same as our function id
if (!t.isIdentifier(node, { name: state.id })) return;
// check if this node is the one referenced
if (!t.isReferenced(node, parent)) return;
// check that we don't have a local variable declared as that removes the need
// for the wrapper
var localDeclar = scope.getBindingIdentifier(state.id);
if (localDeclar !== state.outerDeclar) return;
state.selfReference = true;
this.stop();
}
};
exports.property = function (node, file, scope) {
var key = t.toComputedKey(node, node.key);
if (!t.isLiteral(key)) return node; // we can't set a function id with this
var id = t.toIdentifier(key.value);
key = t.identifier(id);
var state = {
id: id,
selfReference: false,
outerDeclar: scope.getBindingIdentifier(id),
};
scope.traverse(node, visitor, state);
var method = node.value;
if (state.selfReference) {
var templateName = "property-method-assignment-wrapper";
if (method.generator) templateName += "-generator";
node.value = util.template(templateName, {
FUNCTION: method,
FUNCTION_ID: key,
FUNCTION_KEY: scope.generateUidIdentifier(id),
WRAPPER_KEY: scope.generateUidIdentifier(id + "Wrapper")
});
} else {
method.id = key;
}
};

View File

@@ -1,3 +0,0 @@
{
"blacklist": ["useStrict"]
}

View File

@@ -1,7 +0,0 @@
(function () {
function GET_OUTER_ID() {
return ID;
}
return FUNCTION;
})()

View File

@@ -1,33 +0,0 @@
"use strict";
var t = require("../../../types");
exports.secondPass = true;
exports.BlockStatement =
exports.Program = function (node, parent, scope, file) {
if (!node._declarations) return;
var kinds = {};
var kind;
for (var i in node._declarations) {
var declar = node._declarations[i];
kind = declar.kind || "var";
var declarNode = t.variableDeclarator(declar.id, declar.init);
if (declar.init) {
node.body.unshift(file.attachAuxiliaryComment(t.variableDeclaration(kind, [declarNode])));
} else {
kinds[kind] = kinds[kind] || [];
kinds[kind].push(declarNode);
}
}
for (kind in kinds) {
node.body.unshift(file.attachAuxiliaryComment(t.variableDeclaration(kind, kinds[kind])));
}
node._declarations = null;
};

View File

@@ -1,95 +0,0 @@
"use strict";
var t = require("../../../types");
var util = require("../../../util");
var propertyFunctionVisitor = {
enter: function (node, parent, scope, state) {
if (t.isReferencedIdentifier(node, parent, { name: state.name }) && scope.getBindingIdentifier(node.name) === state.binding) {
return state.getOuter();
}
}
};
//exports.ArrowFunctionExpression =
exports.FunctionExpression = function (node, parent, scope) {
// has an `id` so we don't need to infer one
if (node.id) return;
var id;
if (t.isProperty(parent) && parent.kind === "init" && !parent.computed) {
// { foo: function () {} };
id = parent.key;
} else if (t.isVariableDeclarator(parent)) {
// var foo = function () {};
id = parent.id;
} else {
return;
}
if (!t.isIdentifier(id)) return;
var name = t.toIdentifier(id.name);
id = t.identifier(name);
// check to see if we have a local binding of the id we're setting inside of
// the function, this is important as there are caveats associated
var bindingInfo = scope.getOwnBindingInfo(name);
if (bindingInfo) {
if (bindingInfo.type === "param") {
// safari will blow up in strict mode with code like:
//
// var t = function t(t) {};
//
// with the error:
//
// Cannot declare a parameter named 't' as it shadows the name of a
// strict mode function.
//
// this isn't to the spec and they've invented this behaviour which is
// **extremely** annoying so we avoid setting the name if it has a param
// with the same id
} else {
// otherwise it's defined somewhere in scope like:
//
// var t = function () {
// var t = 2;
// };
//
// so we can safely just set the id and move along as it shadows the
// bound function id
node.id = id;
}
return;
}
//
var binding = scope.getBindingIdentifier(name);
var outerId;
scope.traverse(node, propertyFunctionVisitor, {
name: name,
binding: binding,
getOuter: function () {
return t.callExpression(
outerId || (outerId = scope.generateUidIdentifier("getOuter")),
[]
);
}
});
node.id = id;
if (outerId) {
return util.template("named-func", {
GET_OUTER_ID: outerId,
FUNCTION: node,
ID: id
});
}
};

View File

@@ -1,7 +1,7 @@
{
"name": "babel",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "4.4.2",
"version": "4.5.1",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://babeljs.io/",
"repository": "babel/babel",
@@ -36,12 +36,12 @@
"test": "make test"
},
"dependencies": {
"acorn-babel": "0.11.1-33",
"acorn-babel": "0.11.1-34",
"ast-types": "~0.6.1",
"chalk": "^0.5.1",
"chalk": "^1.0.0",
"chokidar": "^0.12.6",
"commander": "^2.6.0",
"core-js": "^0.5.4",
"core-js": "^0.6.1",
"debug": "^2.1.1",
"detect-indent": "^3.0.0",
"estraverse": "^1.9.1",
@@ -49,13 +49,14 @@
"fs-readdir-recursive": "^0.1.0",
"globals": "^6.2.0",
"is-integer": "^1.0.4",
"js-tokenizer": "^1.3.3",
"js-tokens": "0.4.1",
"leven": "^1.0.1",
"line-numbers": "0.2.0",
"lodash": "^3.2.0",
"output-file-sync": "^1.1.0",
"path-is-absolute": "^1.0.0",
"private": "^0.1.6",
"regenerator-babel": "0.8.10-2",
"regenerator-babel": "0.8.13-1",
"regexpu": "^1.1.1",
"repeating": "^1.1.2",
"shebang-regex": "^1.0.0",
@@ -66,11 +67,11 @@
"trim-right": "^1.0.0"
},
"devDependencies": {
"babel": "4.5.0",
"browserify": "^8.1.3",
"chai": "^2.0.0",
"esvalid": "^1.1.0",
"istanbul": "^0.3.5",
"jscs": "^1.11.3",
"jshint": "^2.6.0",
"jshint-stylish": "^1.0.0",
"matcha": "^0.6.0",

View File

@@ -1,7 +1,7 @@
{
"name": "babel-runtime",
"description": "babel selfContained runtime",
"version": "4.4.1",
"version": "4.5.0",
"repository": "babel/babel",
"author": "Sebastian McKenzie <sebmck@gmail.com>"
}

View File

@@ -4,6 +4,7 @@ require("../../polyfill");
var sourceMapSupport = require("source-map-support");
var registerCache = require("./cache");
var resolveRc = require("./resolve-rc");
var extend = require("lodash/object/extend");
var babel = require("../node");
var each = require("lodash/collection/each");
@@ -44,7 +45,10 @@ var mtime = function (filename) {
var compile = function (filename) {
var result;
var cacheKey = filename + ":" + JSON.stringify(transformOpts);
var opts = extend({}, transformOpts);
resolveRc(filename, opts);
var cacheKey = filename + ":" + JSON.stringify(opts);
if (cache) {
var cached = cache[cacheKey];
@@ -54,10 +58,10 @@ var compile = function (filename) {
}
if (!result) {
result = babel.transformFileSync(filename, extend({
result = babel.transformFileSync(filename, extend(opts, {
sourceMap: true,
ast: false
}, transformOpts));
}));
}
if (cache) {

View File

@@ -0,0 +1,50 @@
"use strict";
var merge = require("lodash/object/merge");
var path = require("path");
var fs = require("fs");
var cache = {};
function exists(filename) {
var cached = cache[filename];
if (cached != null) return cached;
return cache[filename] = fs.existsSync(filename);
}
module.exports = function (loc, opts) {
var rel = ".babelrc";
opts = opts || {};
function find(start, rel) {
var file = path.join(start, rel);
if (exists(file)) {
var content = fs.readFileSync(file, "utf8");
var json;
try {
json = JSON.parse(content);
} catch (err) {
err.message = file + ": " + err.message;
throw err;
}
if (json.breakConfig) return;
merge(opts, json, function(a, b) {
if (Array.isArray(a)) {
return a.concat(b);
}
});
}
var up = path.dirname(start);
if (up !== start) { // root
find(up, rel);
}
}
find(loc, rel);
return opts;
};

View File

@@ -40,16 +40,14 @@ exports.JSXExpressionContainer = function (node, print) {
};
exports.JSXElement = function (node, print) {
var self = this;
var open = node.openingElement;
print(open);
if (open.selfClosing) return;
this.indent();
each(node.children, function (child) {
each(node.children, (child) => {
if (t.isLiteral(child)) {
self.push(child.value);
this.push(child.value);
} else {
print(child);
}

View File

@@ -58,8 +58,6 @@ exports.ExportDeclaration = function (node, print) {
};
exports.ImportDeclaration = function (node, print) {
var self = this;
this.push("import ");
if (node.isType) {
@@ -70,16 +68,16 @@ exports.ImportDeclaration = function (node, print) {
if (specfiers && specfiers.length) {
var foundImportSpecifier = false;
each(node.specifiers, function (spec, i) {
each(node.specifiers, (spec, i) => {
if (+i > 0) {
self.push(", ");
this.push(", ");
}
var isDefault = t.isSpecifierDefault(spec);
if (!isDefault && spec.type !== "ImportBatchSpecifier" && !foundImportSpecifier) {
foundImportSpecifier = true;
self.push("{ ");
this.push("{ ");
}
print(spec);

View File

@@ -15,16 +15,15 @@ exports.TemplateLiteral = function (node, print) {
this.push("`");
var quasis = node.quasis;
var self = this;
var len = quasis.length;
each(quasis, function (quasi, i) {
each(quasis, (quasi, i) => {
print(quasi);
if (i + 1 < len) {
self.push("${ ");
this.push("${ ");
print(node.expressions[i]);
self.push(" }");
this.push(" }");
}
});

View File

@@ -58,23 +58,22 @@ exports.Property = function (node, print) {
exports.ArrayExpression =
exports.ArrayPattern = function (node, print) {
var elems = node.elements;
var self = this;
var len = elems.length;
this.push("[");
each(elems, function (elem, i) {
each(elems, (elem, i) => {
if (!elem) {
// If the array expression ends with a hole, that hole
// will be ignored by the interpreter, but if it ends with
// two (or more) holes, we need to write out two (or more)
// commas so that the resulting code is interpreted with
// both (all) of the holes.
self.push(",");
this.push(",");
} else {
if (i > 0) self.push(" ");
if (i > 0) this.push(" ");
print(elem);
if (i < len - 1) self.push(",");
if (i < len - 1) this.push(",");
}
});

View File

@@ -105,20 +105,18 @@ CodeGenerator.prototype.generate = function () {
};
CodeGenerator.prototype.buildPrint = function (parent) {
var self = this;
var print = function (node, opts) {
return self.print(node, parent, opts);
var print = (node, opts) => {
return this.print(node, parent, opts);
};
print.sequence = function (nodes, opts) {
print.sequence = (nodes, opts) => {
opts = opts || {};
opts.statement = true;
return self.printJoin(print, nodes, opts);
return this.printJoin(print, nodes, opts);
};
print.join = function (nodes, opts) {
return self.printJoin(print, nodes, opts);
print.join = (nodes, opts) => {
return this.printJoin(print, nodes, opts);
};
print.list = function (items, opts) {
@@ -127,12 +125,12 @@ CodeGenerator.prototype.buildPrint = function (parent) {
print.join(items, opts);
};
print.block = function (node) {
return self.printBlock(print, node);
print.block = (node) => {
return this.printBlock(print, node);
};
print.indentOnComments = function (node) {
return self.printAndIndentOnComments(print, node);
print.indentOnComments = (node) => {
return this.printAndIndentOnComments(print, node);
};
return print;
@@ -150,11 +148,9 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
this.format.concise = true;
}
var self = this;
opts = opts || {};
var newline = function (leading) {
var newline = (leading) => {
if (!opts.statement && !n.isUserWhitespacable(node, parent)) {
return;
}
@@ -164,9 +160,9 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
if (node.start != null && !node._ignoreUserWhitespace) {
// user node
if (leading) {
lines = self.whitespace.getNewlinesBefore(node);
lines = this.whitespace.getNewlinesBefore(node);
} else {
lines = self.whitespace.getNewlinesAfter(node);
lines = this.whitespace.getNewlinesAfter(node);
}
} else {
// generated node
@@ -178,10 +174,10 @@ CodeGenerator.prototype.print = function (node, parent, opts) {
if (needs(node, parent)) lines++;
// generated nodes can't add starting file whitespace
if (!self.buffer.buf) lines = 0;
if (!this.buffer.buf) lines = 0;
}
self.newline(lines);
this.newline(lines);
};
if (this[node.type]) {
@@ -224,28 +220,27 @@ CodeGenerator.prototype.printJoin = function (print, nodes, opts) {
opts = opts || {};
var self = this;
var len = nodes.length;
var len = nodes.length;
if (opts.indent) self.indent();
if (opts.indent) this.indent();
each(nodes, function (node, i) {
each(nodes, (node, i) => {
print(node, {
statement: opts.statement,
addNewlines: opts.addNewlines,
after: function () {
after: () => {
if (opts.iterator) {
opts.iterator(node, i);
}
if (opts.separator && i < len - 1) {
self.push(opts.separator);
this.push(opts.separator);
}
}
});
});
if (opts.indent) self.dedent();
if (opts.indent) this.dedent();
};
CodeGenerator.prototype.printAndIndentOnComments = function (print, node) {
@@ -289,14 +284,13 @@ CodeGenerator.prototype.getComments = function (key, node, parent) {
var comments = [];
var nodes = [node];
var self = this;
if (t.isExpressionStatement(node)) {
nodes.push(node.argument);
}
each(nodes, function (node) {
comments = comments.concat(self._getComments(key, node));
each(nodes, (node) => {
comments = comments.concat(this._getComments(key, node));
});
return comments;
@@ -312,13 +306,11 @@ CodeGenerator.prototype._printComments = function (comments) {
if (!this.format.comments) return;
if (!comments || !comments.length) return;
var self = this;
each(comments, function (comment) {
each(comments, (comment) => {
var skip = false;
// find the original comment in the ast and set it as displayed
each(self.ast.comments, function (origComment) {
each(this.ast.comments, function (origComment) {
if (origComment.start === comment.start) {
// comment has already been output
if (origComment._displayed) skip = true;
@@ -331,38 +323,38 @@ CodeGenerator.prototype._printComments = function (comments) {
if (skip) return;
// whitespace before
self.newline(self.whitespace.getNewlinesBefore(comment));
this.newline(this.whitespace.getNewlinesBefore(comment));
var column = self.position.column;
var val = self.generateComment(comment);
var column = this.position.column;
var val = this.generateComment(comment);
if (column && !self.isLast(["\n", " ", "[", "{"])) {
self._push(" ");
if (column && !this.isLast(["\n", " ", "[", "{"])) {
this._push(" ");
column++;
}
//
if (comment.type === "Block" && self.format.indent.adjustMultilineComment) {
if (comment.type === "Block" && this.format.indent.adjustMultilineComment) {
var offset = comment.loc.start.column;
if (offset) {
var newlineRegex = new RegExp("\\n\\s{1," + offset + "}", "g");
val = val.replace(newlineRegex, "\n");
}
var indent = Math.max(self.indentSize(), column);
var indent = Math.max(this.indentSize(), column);
val = val.replace(/\n/g, "\n" + repeating(" ", indent));
}
if (column === 0) {
val = self.getIndent() + val;
val = this.getIndent() + val;
}
//
self._push(val);
this._push(val);
// whitespace after
self.newline(self.whitespace.getNewlinesAfter(comment));
this.newline(this.whitespace.getNewlinesAfter(comment));
});
};

View File

@@ -0,0 +1,91 @@
var lineNumbers = require("line-numbers");
var repeating = require("repeating");
var jsTokens = require("js-tokens");
var esutils = require("esutils");
var chalk = require("chalk");
var ary = require("lodash/function/ary");
var defs = {
string: chalk.red,
punctuation: chalk.white.bold,
operator: chalk.white.bold,
curly: chalk.green,
parens: chalk.blue.bold,
square: chalk.yellow,
name: chalk.white,
keyword: chalk.cyan,
number: chalk.magenta,
regex: chalk.magenta,
comment: chalk.grey,
invalid: chalk.inverse
};
var newline = /\r\n|[\n\r\u2028\u2029]/;
var highlight = function (text) {
var tokenType = function (match) {
var token = jsTokens.matchToToken(match);
if (token.type === "name" && esutils.keyword.isKeywordES6(token.value)) {
return "keyword";
}
if (token.type === "punctuation") {
switch (token.value) {
case "{":
case "}":
return "curly";
case "(":
case ")":
return "parens";
case "[":
case "]":
return "square";
}
}
return token.type;
};
return text.replace(jsTokens, function (match) {
var type = tokenType(arguments);
if (type in defs) {
var colorize = ary(defs[type], 1);
return match.split(newline).map(colorize).join("\n");
}
return match;
});
};
module.exports = function (lines, lineNumber, colNumber) {
colNumber = Math.max(colNumber, 0);
if (chalk.supportsColor) {
lines = highlight(lines);
}
lines = lines.split(newline);
var start = Math.max(lineNumber - 3, 0);
var end = Math.min(lines.length, lineNumber + 3);
if (!lineNumber && !colNumber) {
start = 0;
end = lines.length;
}
return "\n" + lineNumbers(lines.slice(start, end), {
start: start + 1,
before: " ",
after: " | ",
transform: function (params) {
if (params.number !== lineNumber) {
return;
}
if (colNumber) {
params.line += "\n" + params.before + repeating(" ", params.width) +
params.after + repeating(" ", colNumber - 1) + "^";
}
params.before = params.before.replace(/^./, ">");
}
}).join("\n");
};

View File

@@ -176,7 +176,7 @@ File.prototype.normalizeOptions = function (opts) {
}
if (opts.externalHelpers) {
this.set("runtimeIdentifier", t.identifier("babelHelpers"));
this.set("helpersNamespace", t.identifier("babelHelpers"));
}
opts.blacklist = transform._ensureTransformerNames("blacklist", opts.blacklist);
@@ -333,7 +333,7 @@ File.prototype.addHelper = function (name) {
var declar = program._declarations && program._declarations[name];
if (declar) return declar.id;
var runtime = this.get("runtimeIdentifier");
var runtime = this.get("helpersNamespace");
if (runtime) {
name = t.identifier(t.toIdentifier(name));
return t.memberExpression(runtime, name);
@@ -370,8 +370,6 @@ File.prototype.addCode = function (code) {
};
File.prototype.parse = function (code) {
var self = this;
code = this.addCode(code);
var opts = this.opts;
@@ -379,9 +377,9 @@ File.prototype.parse = function (code) {
opts.allowImportExportEverywhere = this.isLoose("es6.modules");
opts.strictMode = this.transformers.useStrict.canRun();
return parse(opts, code, function (tree) {
self.transform(tree);
return self.generate();
return parse(opts, code, (tree) => {
this.transform(tree);
return this.generate();
});
};

View File

@@ -44,16 +44,19 @@ module.exports = function (exports, opts) {
};
exports.JSXAttribute = {
exit: function (node) {
var value = node.value || t.literal(true);
enter: function (node) {
var value = node.value;
if (t.isLiteral(value) && isString(value.value)) {
value.value = value.value.replace(/\n\s+/g, " ");
}
},
exit: function (node) {
var value = node.value || t.literal(true);
return t.inherits(t.property("init", node.name, value), node);
}
};
exports.JSXOpeningElement = {
exit: function (node, parent, scope, file) {
var tagExpr = node.name;

View File

@@ -0,0 +1,118 @@
"use strict";
var util = require("../../util");
var t = require("../../types");
var visitor = {
enter: function (node, parent, scope, state) {
// check if this node is a referenced identifier that matches the same as our
// function id
if (!t.isReferencedIdentifier(node, parent, { name: state.name })) return;
// check that we don't have a local variable declared as that removes the need
// for the wrapper
var localDeclar = scope.getBindingIdentifier(state.name);
if (localDeclar !== state.outerDeclar) return;
state.selfReference = true;
this.stop();
}
};
var wrap = function (state, method, id, scope) {
if (state.selfReference) {
var templateName = "property-method-assignment-wrapper";
if (method.generator) templateName += "-generator";
return util.template(templateName, {
FUNCTION: method,
FUNCTION_ID: id,
FUNCTION_KEY: scope.generateUidIdentifier(id.name),
WRAPPER_KEY: scope.generateUidIdentifier(id.name + "Wrapper")
});
} else {
method.id = id;
return method;
}
};
var visit = function (node, name, scope) {
var state = {
selfAssignment: false,
selfReference: false,
outerDeclar: scope.getBindingIdentifier(name),
references: [],
name: name,
};
// check to see if we have a local binding of the id we're setting inside of
// the function, this is important as there are caveats associated
var bindingInfo = null; // todo: proper scope not being passed in es6/classes // scope.getOwnBindingInfo(name);
if (bindingInfo) {
if (bindingInfo.kind === "param") {
// safari will blow up in strict mode with code like:
//
// var t = function t(t) {};
//
// with the error:
//
// Cannot declare a parameter named 't' as it shadows the name of a
// strict mode function.
//
// this isn't to the spec and they've invented this behaviour which is
// **extremely** annoying so we avoid setting the name if it has a param
// with the same id
state.selfReference = true;
} else {
// otherwise it's defined somewhere in scope like:
//
// var t = function () {
// var t = 2;
// };
//
// so we can safely just set the id and move along as it shadows the
// bound function id
}
} else {
scope.traverse(node, visitor, state);
}
return state;
};
exports.property = function (node, file, scope) {
var key = t.toComputedKey(node, node.key);
if (!t.isLiteral(key)) return node; // we can't set a function id with this
var name = t.toIdentifier(key.value);
var id = t.identifier(name);
var method = node.value;
var state = visit(method, name, scope);
node.value = wrap(state, method, id, scope);
};
exports.bare = function (node, parent, scope) {
// has an `id` so we don't need to infer one
if (node.id) return;
var id;
if (t.isProperty(parent) && parent.kind === "init" && !parent.computed) {
// { foo: function () {} };
id = parent.key;
} else if (t.isVariableDeclarator(parent)) {
// var foo = function () {};
id = parent.id;
} else {
return;
}
if (!t.isIdentifier(id)) return;
var name = t.toIdentifier(id.name);
id = t.identifier(name);
var state = visit(node, name, scope);
return wrap(state, node, id, scope);
};

View File

@@ -0,0 +1,21 @@
"use strict";
var t = require("../../types");
exports.has = function (node) {
var first = node.body[0];
return t.isExpressionStatement(first) && t.isLiteral(first.expression, { value: "use strict" });
};
exports.wrap = function (node, callback) {
var useStrictNode;
if (exports.has(node)) {
useStrictNode = node.body.shift();
}
callback();
if (useStrictNode) {
node.body.unshift(useStrictNode);
}
};

View File

@@ -0,0 +1,3 @@
{
"blacklist": ["useStrict", "es6.blockScoping"]
}

Some files were not shown because too many files have changed in this diff Show More