Compare commits

...

42 Commits

Author SHA1 Message Date
Sebastian McKenzie
28c4c18ee2 v3.0.9 2015-01-28 20:08:49 +11:00
Sebastian McKenzie
968db67d0a add in pattern support to t.isReferenced 2015-01-28 20:06:49 +11:00
Sebastian McKenzie
b22ef22e36 add missing semicolon 2015-01-28 20:03:29 +11:00
Sebastian McKenzie
044ce45d98 add 3.0.9 changelog 2015-01-28 20:02:49 +11:00
Sebastian McKenzie
69f2a0d3f1 better t.toIdentifier behaviour that doesn't camelcase on underscores - fixes #610 2015-01-28 20:01:55 +11:00
Sebastian McKenzie
4b66dcb738 more reliable t.isReferenced - fixes #610 2015-01-28 19:58:20 +11:00
Sebastian McKenzie
dfc6f1d1cf add comment explaining what the modules-split transformer does 2015-01-28 18:40:33 +11:00
Sebastian McKenzie
a64e040ac7 3.0.8 2015-01-28 18:36:45 +11:00
Sebastian McKenzie
4f9414dbb0 v3.0.8 2015-01-28 18:36:22 +11:00
Sebastian McKenzie
bc6b31efbc split up function declarations from their exports - fixes #609 2015-01-28 18:34:43 +11:00
Sebastian McKenzie
244aed1ae9 3.0.7 2015-01-28 18:20:04 +11:00
Sebastian McKenzie
4fdb2ce939 v3.0.7 2015-01-28 18:18:23 +11:00
Sebastian McKenzie
fe57eb554c add 3.0.7 changelog 2015-01-28 18:16:44 +11:00
Sebastian McKenzie
3b798943e3 upgrade core-js and use a caret, make all other dependency versions static 2015-01-28 18:15:14 +11:00
Sebastian McKenzie
4ff66a5cfc add id to a function expression scope 2015-01-28 18:14:52 +11:00
Sebastian McKenzie
5477a990bc construct null object for types.getIds 2015-01-28 18:09:38 +11:00
Sebastian McKenzie
656ca422a5 3.0.6 2015-01-28 17:52:09 +11:00
Sebastian McKenzie
7a3071a094 v3.0.6 2015-01-28 17:51:02 +11:00
Sebastian McKenzie
77361582f4 don't stop block scoped variable traversal on any scope, just skip it and fix block statement for parent delegation - fixes #605 2015-01-28 17:48:37 +11:00
Sebastian McKenzie
f585039430 3.0.5 2015-01-28 15:23:11 +11:00
Sebastian McKenzie
21dcb6037a v3.0.5 2015-01-28 15:21:38 +11:00
Sebastian McKenzie
d10d96d19a fix unused iife declaration 2015-01-28 15:19:50 +11:00
Sebastian McKenzie
64766eea44 add more reliable iife detection for default parameter independent scope 2015-01-28 15:18:50 +11:00
Sebastian McKenzie
a9e682836b 3.0.4 2015-01-28 14:52:05 +11:00
Sebastian McKenzie
f504b8d529 v3.0.4 2015-01-28 14:49:55 +11:00
Sebastian McKenzie
30b2b55c86 remove badges from readme because noone cares 2015-01-28 14:48:13 +11:00
Sebastian McKenzie
836bc3a9a4 only check for duplicates for let variables 2015-01-28 14:47:09 +11:00
Sebastian McKenzie
630bfcc6cd add 3.0.x changelogs 2015-01-28 14:44:07 +11:00
Sebastian McKenzie
117203010a don't stop block variable scope finding on first hit 2015-01-28 14:39:46 +11:00
Sebastian McKenzie
f0986fe9c7 3.0.3 2015-01-28 14:39:01 +11:00
Sebastian McKenzie
4379441277 v3.0.3 2015-01-28 14:17:26 +11:00
Sebastian McKenzie
a955af06e0 remove opts from transform output 2015-01-28 14:14:55 +11:00
Sebastian McKenzie
8f69e59f29 ignore underscored options - fixes #29 2015-01-28 14:14:33 +11:00
Sebastian McKenzie
efda5ca897 3.0.2 2015-01-28 13:59:29 +11:00
Sebastian McKenzie
8a99fd3c8d v3.0.2 2015-01-28 13:53:19 +11:00
Sebastian McKenzie
614ce4de0a add common plugin options to validOptions just to be safe 2015-01-28 13:48:45 +11:00
Sebastian McKenzie
06b2cffbfc 3.0.1 2015-01-28 13:17:54 +11:00
Sebastian McKenzie
f3dfe9571e v3.0.1 2015-01-28 13:17:34 +11:00
Sebastian McKenzie
9b9e2c4ac0 remove iojs from travis 2015-01-28 13:15:45 +11:00
Sebastian McKenzie
28e0b17a81 3.0.0 2015-01-28 13:14:05 +11:00
Sebastian McKenzie
b02f10053e fix publish-runtime task 2015-01-28 13:14:00 +11:00
Sebastian McKenzie
979dcd5330 downgrade kexec 2015-01-28 13:13:52 +11:00
12 changed files with 173 additions and 84 deletions

View File

@@ -3,7 +3,6 @@ language: node_js
node_js:
- "0.10"
- "0.11"
- iojs
branches:
except:

View File

@@ -11,6 +11,55 @@
_Note: Gaps between patch versions are faulty/broken releases._
## 3.0.9
* **Bug Fix**
* Make `t.isReferenced` more powerful, actually take into consideration all contexts were identifier nodes aren't actually references.
* Don't camelcase underscores when converting a string to a valid identifier.
## 3.0.8
* **Bug Fix**
* Split up default function declaration exports due to regenerator destroying the parent export declaration.
## 3.0.7
* **Internal**
* Upgrade `core-js` to `0.4.9`.
* **Bug Fix**
* Add id to function express scope tracking.
## 3.0.6
* **Bug Fix**
* Fix block scope variable tracking stopping whenever it hits a new scope.
* Fix block scope variable tracking breaking on all block statement scopes that have a for loop parent.
## 3.0.5
* **Internal**
* More reliable default parameter scope.
## 3.0.4
* **Bug Fix**
* Remove traversal stops from block scope tracking.
## 3.0.3
* **Internal**
* Ignore options starting with `_`.
## 3.0.2
* **Internal**
* Add common plugin options to valid options list.
## 3.0.1
* **Internal**
* Downgrade `kexec` as `1.1.0` throws compilation errors.
## 3.0.0
* **Polish**

View File

@@ -93,6 +93,7 @@ publish:
publish-runtime:
cd packages; \
node build-runtime.js; \
cd 6to5-runtime; \
npm publish
publish-core:

View File

@@ -2,28 +2,6 @@
<img alt="6to5" src="https://raw.githubusercontent.com/6to5/logo/master/logo.png" width="546">
</p>
<p align="center">
<a href="https://gratipay.com/sebmck">
<img alt="Gratipay" src="https://img.shields.io/gratipay/sebmck.svg?style=flat">
</a>
<a href="https://travis-ci.org/6to5/6to5">
<img alt="Travis Status" src="http://img.shields.io/travis/6to5/6to5/master.svg?style=flat&amp;label=travis">
</a>
<a href="https://codeclimate.com/github/6to5/6to5">
<img alt="Code Climate Score" src="http://img.shields.io/codeclimate/github/6to5/6to5.svg?style=flat">
</a>
<a href="https://codeclimate.com/github/6to5/6to5">
<img alt="Coverage" src="http://img.shields.io/codeclimate/coverage/github/6to5/6to5.svg?style=flat">
</a>
<a href="https://david-dm.org/6to5/6to5">
<img alt="Dependency Status" src="http://img.shields.io/david/6to5/6to5.svg?style=flat">
</a>
</p>
<p align="center">
<strong>6to5</strong> turns ES6+ code into vanilla ES5, so you can use next generation features <strong>today.</strong>
</p>

View File

@@ -70,14 +70,19 @@ File.validOptions = [
"ast",
"format",
"playground",
"experimental"
"experimental",
// these are used by plugins
"ignore",
"only",
"extensions"
];
File.normaliseOptions = function (opts) {
opts = clone(opts);
for (var key in opts) {
if (File.validOptions.indexOf(key) < 0) {
if (key[0] !== "_" && File.validOptions.indexOf(key) < 0) {
throw new ReferenceError("Unknown option: " + key);
}
}
@@ -320,7 +325,7 @@ File.prototype.transform = function (ast) {
this.ast = ast;
this.lastStatements = t.getLastStatements(ast.program);
this.scope = new Scope(ast.program, null, this);
this.scope = new Scope(ast.program, ast, null, this);
this.moduleFormatter = this.getModuleFormatter(this.opts.modules);
var astRun = function (key) {
@@ -344,7 +349,6 @@ File.prototype.generate = function () {
var result = {
code: "",
opts: opts,
map: null,
ast: null
};

View File

@@ -1,7 +1,8 @@
"use strict";
var util = require("../../../util");
var t = require("../../../types");
var traverse = require("../../../traverse");
var util = require("../../../util");
var t = require("../../../types");
var hasDefaults = function (node) {
for (var i = 0; i < node.params.length; i++) {
@@ -10,12 +11,20 @@ var hasDefaults = function (node) {
return false;
};
var iifeVisitor = {
enter: function (node, parent, scope, context, state) {
if (t.isReferencedIdentifier(node, parent) && scope.hasOwn(node.name)) {
state.iife = true;
context.stop();
}
}
};
exports.Function = function (node, parent, scope) {
if (!hasDefaults(node)) return;
t.ensureBlock(node);
var iife = false;
var body = [];
var argsIdentifier = t.identifier("arguments");
@@ -23,6 +32,8 @@ exports.Function = function (node, parent, scope) {
var lastNonDefaultParam = 0;
var state = { iife: false, scope: scope };
for (var i = 0; i < node.params.length; i++) {
var param = node.params[i];
@@ -36,10 +47,12 @@ exports.Function = function (node, parent, scope) {
node.params[i] = scope.generateUidIdentifier("x");
// we're accessing a variable that's already defined within this function
var localDeclar = scope.get(left.name, true);
if (localDeclar !== left) {
iife = true;
if (!state.iife) {
if (t.isIdentifier(right) && scope.hasOwn(right.name)) {
state.iife = true;
} else {
traverse(right, iifeVisitor, scope, state);
}
}
var defNode = util.template("default-parameter", {
@@ -55,7 +68,7 @@ exports.Function = function (node, parent, scope) {
// we need to cut off all trailing default parameters
node.params = node.params.slice(0, lastNonDefaultParam);
if (iife) {
if (state.iife) {
var container = t.functionExpression(null, [], node.body, node.generator);
container._aliasFunction = true;

View File

@@ -1,5 +1,11 @@
"use strict";
// in this transformer we have to split up classes and function declarations
// from their exports. why? because sometimes we need to replace classes with
// nodes that aren't allowed in the same contexts. also, if you're exporting
// a generator function as a default then regenerator will destroy the export
// declaration and leave a variable declaration in it's place... yeah, handy.
var t = require("../../../types");
exports.ExportDeclaration = function (node, parent, scope) {
@@ -16,6 +22,10 @@ exports.ExportDeclaration = function (node, parent, scope) {
]);
node.declaration = temp;
return [declar, node];
} else if (t.isFunctionDeclaration(declar)) {
node._blockHoist = 2;
node.declaration = declar.id;
return [declar, node];
}
} else {
if (t.isFunctionDeclaration(declar)) {

View File

@@ -111,7 +111,7 @@ TraversalContext.prototype.visitNode = function (obj, key, opts, scope, parent,
var ourScope = scope;
// we're entering a new scope so let's construct it!
if (t.isScope(node)) {
ourScope = new Scope(node, scope);
ourScope = new Scope(node, parent, scope);
}
node = this.enterNode(obj, key, node, opts.enter, parent, ourScope, state);

View File

@@ -14,15 +14,18 @@ var FOR_KEYS = ["left", "init"];
* within.
*
* @param {Node} block
* @param {Node} parentBlock
* @param {Scope} [parent]
* @param {File} [file]
*/
function Scope(block, parent, file) {
function Scope(block, parentBlock, parent, file) {
this.parent = parent;
this.block = block;
this.file = parent ? parent.file : file;
this.parentBlock = parentBlock;
this.block = block;
var info = this.getInfo();
this.references = info.references;
this.declarations = info.declarations;
@@ -169,8 +172,7 @@ var programReferenceVisitor = {
var blockVariableVisitor = {
enter: function (node, parent, scope, context, add) {
if (t.isBlockScoped(node)) {
add(node, false, true);
context.stop();
add(node, false, t.isLet(node));
} else if (t.isScope(node)) {
context.skip();
}
@@ -197,7 +199,8 @@ Scope.prototype.getInfo = function () {
}
};
if (parent && t.isBlockStatement(block) && t.isFor(parent.block)) {
if (parent && t.isBlockStatement(block) && t.isFor(parent.block, { body: block })) {
// delegate block let declarations to the parent loop
return info;
}
@@ -241,6 +244,14 @@ Scope.prototype.getInfo = function () {
});
}
if (t.isFunctionExpression(block) && block.id) {
if (!t.isProperty(this.parentBlock, { method: true })) {
// SpiderMonkey AST doesn't use MethodDefinition here when it probably
// should since they should be semantically the same?
add(block.id);
}
}
// Program
if (t.isProgram(block)) {

View File

@@ -2,6 +2,7 @@
var toFastProperties = require("../helpers/to-fast-properties");
var esutils = require("esutils");
var object = require("../helpers/object");
var Node = require("./node");
var _ = require("lodash");
@@ -225,7 +226,7 @@ t.prependToMemberExpression = function (member, append) {
};
/**
* Description
* Check if the input `node` is going to be evaluated, ie. is a refernece.
*
* @param {Object} node
* @param {Object} parent
@@ -233,45 +234,70 @@ t.prependToMemberExpression = function (member, append) {
*/
t.isReferenced = function (node, parent) {
// we're a property key and we aren't computed so we aren't referenced
if (t.isProperty(parent) && parent.key === node && !parent.computed) return false;
if (t.isFunction(parent)) {
// we're a function param
if (_.contains(parent.params, node)) return false;
for (var i = 0; i < parent.params.length; i++) {
var param = parent.params[i];
if (param === node) {
return false;
} else if (t.isRestElement(param) && param.argument === node) {
return false;
}
}
if (t.isProperty(parent)) {
return parent.key === node && parent.computed;
}
if (t.isMethodDefinition(parent) && parent.key === node && !parent.computed) {
if (t.isRestElement(parent)) {
return false;
}
// we're a catch clause param
if (t.isCatchClause(parent) && parent.param === node) return false;
if (t.isAssignmentPattern(parent)) {
return parent.right !== node;
}
// we're a variable declarator id so we aren't referenced
if (t.isVariableDeclarator(parent) && parent.id === node) return false;
if (t.isPattern(parent)) {
return false;
}
var isMemberExpression = t.isMemberExpression(parent);
if (t.isFunction(parent)) {
for (var i = 0; i < parent.params.length; i++) {
var param = parent.params[i];
if (param === node) return false;
}
// we're in a member expression and we're the computed property so we're referenced
var isComputedProperty = isMemberExpression && parent.property === node && parent.computed;
return parent.id !== node;
}
// we're in a member expression and we're the object so we're referenced
var isObject = isMemberExpression && parent.object === node;
if (t.isClass(parent)) {
return parent.id !== node;
}
// we are referenced
if (!isMemberExpression || isComputedProperty || isObject) return true;
if (t.isMethodDefinition(parent)) {
return parent.key === node && parent.computed;
}
return false;
if (t.isImportSpecifier(parent)) {
return false;
}
if (t.isImportBatchSpecifier(parent)) {
return false;
}
if (t.isLabeledStatement(parent)) {
return false;
}
if (t.isCatchClause(parent)) {
return parent.param !== node;
}
if (t.isVariableDeclarator(parent)) {
return parent.id !== node;
}
if (t.isMemberExpression(parent)) {
if (parent.property === node && parent.computed) { // PARENT[NODE]
return true;
} else if (parent.object === node) { // NODE.child
return true;
} else {
return false;
}
}
return true;
};
/**
@@ -316,13 +342,10 @@ t.toIdentifier = function (name) {
name = name.replace(/^[-0-9]+/, "");
// camel case
name = name.replace(/[-_\s]+(.)?/g, function (match, c) {
name = name.replace(/[-\s]+(.)?/g, function (match, c) {
return c ? c.toUpperCase() : "";
});
// remove underscores from start of name
name = name.replace(/^\_/, "");
if (!t.isValidIdentifier(name)) {
name = "_" + name;
}
@@ -455,7 +478,7 @@ t.getIds = function (node, map, ignoreTypes) {
ignoreTypes = ignoreTypes || [];
var search = [].concat(node);
var ids = {};
var ids = object();
while (search.length) {
var id = search.shift();

View File

@@ -1,7 +1,7 @@
{
"name": "6to5",
"description": "Turn ES6 code into readable vanilla ES5 with source maps",
"version": "3.0.0",
"version": "3.0.9",
"author": "Sebastian McKenzie <sebmck@gmail.com>",
"homepage": "https://6to5.org/",
"repository": "6to5/6to5",
@@ -37,28 +37,28 @@
"chalk": "^0.5.1",
"chokidar": "0.12.6",
"commander": "2.6.0",
"core-js": "0.4.6",
"detect-indent": "^3.0.0",
"core-js": "^0.4.9",
"detect-indent": "3.0.0",
"estraverse": "1.9.1",
"esutils": "1.1.6",
"esvalid": "1.1.0",
"fs-readdir-recursive": "0.1.0",
"js-tokenizer": "^1.3.3",
"js-tokenizer": "1.3.3",
"lodash": "3.0.0",
"output-file-sync": "^1.1.0",
"output-file-sync": "1.1.0",
"private": "0.1.6",
"regenerator-6to5": "0.8.9-6",
"regexpu": "1.1.0",
"roadrunner": "1.0.4",
"source-map": "0.1.43",
"source-map-support": "0.2.9",
"supports-color": "^1.2.0"
"supports-color": "1.2.0"
},
"devDependencies": {
"browserify": "8.1.1",
"chai": "1.10.0",
"istanbul": "0.3.5",
"jscs": "^1.10.0",
"jscs": "1.10.0",
"jshint": "2.6.0",
"jshint-stylish": "1.0.0",
"matcha": "0.6.0",
@@ -67,6 +67,6 @@
"uglify-js": "2.4.16"
},
"optionalDependencies": {
"kexec": "1.1.1"
"kexec": "1.0.0"
}
}

View File

@@ -1,6 +1,7 @@
{
"name": "6to5-runtime",
"description": "6to5 selfContained runtime",
"version": "2.13.5",
"version": "3.0.8",
"repository": "6to5/6to5",
"author": "Sebastian McKenzie <sebmck@gmail.com>"
}