From ce372281cdd3ffd74a4f481d7a4e8f4ff11494d9 Mon Sep 17 00:00:00 2001 From: Arthur Verschaeve Date: Mon, 29 Jun 2015 12:35:37 +0200 Subject: [PATCH 01/13] Add `path-exists` to `CONTRIBUTING.md` --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 06f0a691c4..5e18d5f29c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -145,6 +145,8 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad + [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) + #### Code Standards From 63f53e37739a2914bef87e80d769e4d4a91539ab Mon Sep 17 00:00:00 2001 From: Arthur Verschaeve Date: Tue, 30 Jun 2015 23:36:52 +0200 Subject: [PATCH 02/13] Remove `user-home` from `CONTRIBUTING.md` In favor of `user-or-tmp` Ref https://github.com/babel/babel/commit/90b8826e735a01f1f2fc3c300f3bbb40179fd8ee --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5e18d5f29c..aac98472d2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -143,10 +143,10 @@ 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. + #### Code Standards From 301df15921c12273cddf53e1d9ba830aba3ac202 Mon Sep 17 00:00:00 2001 From: Arthur Verschaeve Date: Tue, 30 Jun 2015 23:50:44 +0200 Subject: [PATCH 03/13] Add `resolve` to `CONTRIBUTING.md` Introduced in https://github.com/babel/babel/commit/aaf4cbf06f48f9f4476ad814ba6f72e064042ff1 --- CONTRIBUTING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aac98472d2..2cc37d6ae1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -147,6 +147,7 @@ your [`$PATH`](http://unix.stackexchange.com/questions/26047/how-to-correctly-ad + [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 From 456accb4b3d20492af5e3020e066a6d9d226a36a Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 1 Jul 2015 15:37:20 -0700 Subject: [PATCH 04/13] :memo: Add link to ESTree --- doc/node-props.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/node-props.md b/doc/node-props.md index b44470d196..d457a4c375 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. From f3973c8397351c95f9eb7d5a24202ae58ea288cb Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 1 Jul 2015 15:41:15 -0700 Subject: [PATCH 05/13] :memo: clarify how it inherits this --- doc/node-props.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/node-props.md b/doc/node-props.md index d457a4c375..3fec49b615 100644 --- a/doc/node-props.md +++ b/doc/node-props.md @@ -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. From 70c739250b7f291b549c50daea2fad2493475160 Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 1 Jul 2015 15:48:00 -0700 Subject: [PATCH 06/13] :memo: better english --- src/babel/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/babel/messages.js b/src/babel/messages.js index f06f248083..91381589e1 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", From c3b5ed5b3d401bcce80bbe0cdd219d0c3974e7b5 Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 1 Jul 2015 15:51:56 -0700 Subject: [PATCH 07/13] :lipstick: Fix grammatical issue --- src/babel/messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/babel/messages.js b/src/babel/messages.js index 91381589e1..db736b800b 100644 --- a/src/babel/messages.js +++ b/src/babel/messages.js @@ -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", From 4a27b10e8a87eae1294f0cd7faa19bc03dfcb149 Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 1 Jul 2015 15:56:11 -0700 Subject: [PATCH 08/13] :baby: --- src/babel/messages.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/babel/messages.js b/src/babel/messages.js index 91381589e1..b2a53aac06 100644 --- a/src/babel/messages.js +++ b/src/babel/messages.js @@ -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) { From 98695669636be4d75c5fd822e6a389cbeaacd9da Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 1 Jul 2015 15:59:05 -0700 Subject: [PATCH 09/13] remove :skull: comment lines Added in https://github.com/babel/babel/commit/3561efdb8682b561052a23c5c9c869e59311ea01 if this is a style thing you want to keep around then my all means close away. --- packages/build-runtime.js | 2 -- 1 file changed, 2 deletions(-) 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(); From 5b0b7ba226dc2e66d3863d1cc2cacea4c473b5e5 Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 1 Jul 2015 20:30:21 -0700 Subject: [PATCH 10/13] :fork_and_knife: Switch to ternary for return https://www.youtube.com/watch?v=XAbY2cmEsS0 --- src/babel/generation/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/babel/generation/index.js b/src/babel/generation/index.js index a24ade6484..b9c75281e7 100644 --- a/src/babel/generation/index.js +++ b/src/babel/generation/index.js @@ -80,11 +80,7 @@ class CodeGenerator { if (checked >= 3) break; } - if (occurences.single > occurences.double) { - return "single"; - } else { - return "double"; - } + return occurences.single > occurences.double ? "single" : "double"; } static generators = { From 1945f849c37195e64d959a83645a08330c29aeae Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Wed, 1 Jul 2015 20:34:43 -0700 Subject: [PATCH 11/13] Move :white_check_mark: into for block https://www.youtube.com/watch?v=FHDwRECFL8M --- src/babel/generation/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/babel/generation/index.js b/src/babel/generation/index.js index b9c75281e7..b7584b5b65 100644 --- a/src/babel/generation/index.js +++ b/src/babel/generation/index.js @@ -63,9 +63,7 @@ class CodeGenerator { double: 0 }; - var checked = 0; - - for (var i = 0; i < tokens.length; i++) { + for (var i = 0, checked = 0; i < tokens.length; i++) { var token = tokens[i]; if (token.type.label !== "string") continue; From 3f38a836008323ee21f67fdbec123ac68f638537 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Wed, 1 Jul 2015 22:06:05 -0700 Subject: [PATCH 12/13] Properly regenerate scope for replaced nodes - fixes #1773 --- src/babel/traversal/scope/index.js | 2 +- .../transformation/es6.classes/constructor/actual.js | 9 +++++++++ .../es6.classes/constructor/expected.js | 11 ++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) 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; + } +}; From 74c59c94ce3aed9be372224801251e07e8661902 Mon Sep 17 00:00:00 2001 From: Sam Saccone Date: Thu, 2 Jul 2015 16:57:12 -0400 Subject: [PATCH 13/13] :golf: --- src/babel/generation/index.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/babel/generation/index.js b/src/babel/generation/index.js index b7584b5b65..149002bdc2 100644 --- a/src/babel/generation/index.js +++ b/src/babel/generation/index.js @@ -57,28 +57,16 @@ class CodeGenerator { return format; } - static findCommonStringDelimiter(code, tokens) { - var occurences = { - single: 0, - double: 0 - }; - - for (var i = 0, checked = 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"; } - return occurences.single > occurences.double ? "single" : "double"; + if (tokens[0].type.label === "string") { + occurences[code[tokens[0].start]]++; + } + + return this.findCommonStringDelimiter(code, tokens.slice(1), occurences); } static generators = {