diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 06f0a691c4..2cc37d6ae1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -143,8 +143,11 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad + [trim-right](http://ghub.io/trim-right) Trims the rightside whitespace. -+ [user-home](http://ghub.io/user-home) Gets the users home directory. This is used to resolve the babel-node/babel/register cache. ++ [path-exists](https://www.npmjs.com/package/path-exists) Checks if a path exists. (replaces the deprecated `fs.exists` methods) ++ [home-or-tmp](https://github.com/sindresorhus/home-or-tmp) Gets the user home directory with fallback to the system temporary directory. This is used to resolve the babel-node/babel/register cache. + ++ [resolve](https://www.npmjs.com/package/resolve) Implements the [`require.resolve()` algorithm](http://nodejs.org/docs/v0.12.0/api/all.html#all_require_resolve) such that we can `require.resolve()` on behalf of a file asynchronously and synchronously. #### Code Standards diff --git a/doc/node-props.md b/doc/node-props.md index b44470d196..3fec49b615 100644 --- a/doc/node-props.md +++ b/doc/node-props.md @@ -1,5 +1,5 @@ # Properties of nodes -These are properties babel stores in AST node objects for internal use, as opposed to properties that are part of the AST spec (ESTree at the time of this writing). +These are properties babel stores in AST node objects for internal use, as opposed to properties that are part of the AST spec ([ESTree](https://github.com/estree/estree) at the time of this writing). ## `_blockHoist` `node._blockHoist != null` triggers the [block-hoist transformer](/src/babel/transformation/transformers/internal/block-hoist.js). Value should be `true` or an integer in the range `0..3`. `true` is equivalent to `2`. The value indicates whether the node should be hoisted and to what degree. See the source code for more detailed information. @@ -8,4 +8,4 @@ These are properties babel stores in AST node objects for internal use, as oppos Stores a representation of a node's position in the tree and relationship to other nodes. ## `shadow` -A truthy value on a function node triggers the [shadow-functions transformer](/src/babel/transformation/transformers/internal/shadow-functions.js), which transforms the node so that it references (or inherits) `arguments` and `this` from the parent scope. It is invoked for arrow functions, for example. +A truthy value on a function node triggers the [shadow-functions transformer](/src/babel/transformation/transformers/internal/shadow-functions.js), which transforms the node so that it references (or inherits) `arguments` and the `this` context from the parent scope. It is invoked for arrow functions, for example. diff --git a/packages/build-runtime.js b/packages/build-runtime.js index 89902d08f5..962126bfa4 100644 --- a/packages/build-runtime.js +++ b/packages/build-runtime.js @@ -73,7 +73,6 @@ each(File.helpers, function (helperName) { writeFile("regenerator/index.js", readFile("regenerator/runtime-module", true)); writeFile("regenerator/runtime.js", selfContainify(readFile("regenerator/runtime"))); -// var coreDefinitions = require("babel-plugin-runtime/lib/definitions"); @@ -93,6 +92,5 @@ each(paths, function (path) { writeFile("core-js/" + path + ".js", defaultify('require("core-js/library/fn/' + path + '")')); }); -// updatePackage(); diff --git a/src/babel/generation/index.js b/src/babel/generation/index.js index a24ade6484..149002bdc2 100644 --- a/src/babel/generation/index.js +++ b/src/babel/generation/index.js @@ -57,34 +57,16 @@ class CodeGenerator { return format; } - static findCommonStringDelimiter(code, tokens) { - var occurences = { - single: 0, - double: 0 - }; - - var checked = 0; - - for (var i = 0; i < tokens.length; i++) { - var token = tokens[i]; - if (token.type.label !== "string") continue; - - var raw = code.slice(token.start, token.end); - if (raw[0] === "'") { - occurences.single++; - } else { - occurences.double++; - } - - checked++; - if (checked >= 3) break; + static findCommonStringDelimiter(code, tokens, occurences = {"'": 0, "\"": 0}) { + if (tokens.length === 0 || occurences["'"] + occurences["\""] >= 3) { + return occurences["'"] > occurences["\""] ? "single" : "double"; } - if (occurences.single > occurences.double) { - return "single"; - } else { - return "double"; + if (tokens[0].type.label === "string") { + occurences[code[tokens[0].start]]++; } + + return this.findCommonStringDelimiter(code, tokens.slice(1), occurences); } static generators = { diff --git a/src/babel/messages.js b/src/babel/messages.js index f06f248083..8b8fd7d0d4 100644 --- a/src/babel/messages.js +++ b/src/babel/messages.js @@ -1,7 +1,7 @@ import * as util from "util"; export const MESSAGES = { - tailCallReassignmentDeopt: "Function reference has been reassigned so it's probably be dereferenced so we can't optimise this with confidence", + tailCallReassignmentDeopt: "Function reference has been reassigned, so it will probably be dereferenced, therefore we can't optimise this with confidence", JSXNamespacedTags: "Namespace tags are not supported. ReactJSX is not XML.", classesIllegalBareSuper: "Illegal use of bare super", classesIllegalSuperCall: "Direct super call is illegal in non-constructor, use super.$1() instead", @@ -17,7 +17,7 @@ export const MESSAGES = { missingTemplatesDirectory: "no templates directory - this is most likely the result of a broken `npm publish`. Please report to https://github.com/babel/babel/issues", unsupportedOutputType: "Unsupported output type $1", illegalMethodName: "Illegal method name $1", - lostTrackNodePath: "We lost track of this nodes position, likely because the AST was directly manipulated", + lostTrackNodePath: "We lost track of this node's position, likely because the AST was directly manipulated", modulesIllegalExportName: "Illegal export $1", modulesDuplicateDeclarations: "Duplicate module declarations with the same source but in different scopes", @@ -26,7 +26,7 @@ export const MESSAGES = { undeclaredVariableType: "Referencing a type alias outside of a type annotation", undeclaredVariableSuggestion: "Reference to undeclared variable $1 - did you mean $2?", - traverseNeedsParent: "Must pass a scope and parentPath unless traversing a Program/File got a $1 node", + traverseNeedsParent: "You must pass a scope and parentPath unless traversing a Program/File got a $1 node", traverseVerifyRootFunction: "You passed `traverse()` a function when it expected a visitor object, are you sure you didn't mean `{ enter: Function }`?", traverseVerifyVisitorProperty: "You passed `traverse()` a visitor object with the property $1 that has the invalid property $2", traverseVerifyNodeType: "You gave us a visitor for the node type $1 but it's not a valid type", @@ -37,7 +37,7 @@ export const MESSAGES = { pluginNotTransformer: "The plugin $1 didn't export a Plugin instance", pluginUnknown: "Unknown plugin $1", - pluginNotFile: "Plugin $1 is resolving to a different Babel version to what is doing the actual transformation..." + pluginNotFile: "Plugin $1 is resolving to a different Babel version than what is performing the transformation." }; export function get(key: String, ...args) { diff --git a/src/babel/traversal/scope/index.js b/src/babel/traversal/scope/index.js index 158c85388a..646666738c 100644 --- a/src/babel/traversal/scope/index.js +++ b/src/babel/traversal/scope/index.js @@ -146,7 +146,7 @@ export default class Scope { } var cached = path.getData("scope"); - if (cached && cached.parent === parent) { + if (cached && cached.parent === parent && cached.block === path.node) { return cached; } else { path.setData("scope", this); diff --git a/test/core/fixtures/transformation/es6.classes/constructor/actual.js b/test/core/fixtures/transformation/es6.classes/constructor/actual.js index c968e6c108..33c274123a 100644 --- a/test/core/fixtures/transformation/es6.classes/constructor/actual.js +++ b/test/core/fixtures/transformation/es6.classes/constructor/actual.js @@ -10,3 +10,12 @@ class Foo extends Bar { this.state = "test"; } } + +class ConstructorScoping { + constructor(){ + let bar; + { + let bar; + } + } +} diff --git a/test/core/fixtures/transformation/es6.classes/constructor/expected.js b/test/core/fixtures/transformation/es6.classes/constructor/expected.js index 7169ce082f..9aefa96a1c 100644 --- a/test/core/fixtures/transformation/es6.classes/constructor/expected.js +++ b/test/core/fixtures/transformation/es6.classes/constructor/expected.js @@ -16,4 +16,13 @@ var Foo = (function (_Bar) { babelHelpers.inherits(Foo, _Bar); return Foo; -})(Bar); \ No newline at end of file +})(Bar); + +var ConstructorScoping = function ConstructorScoping() { + babelHelpers.classCallCheck(this, ConstructorScoping); + + var bar = undefined; + { + var _bar = undefined; + } +};